Site icon Web Niraj

Facebook API: Getting Friends Using Graph API 2.0 and PHP SDK 4.0.x

With the introduction of the Facebook Graph API 2.0, access a user’s friends list was removed and limited to just friends who use the same application. However, Facebook added two new APIs to allow retrieval of Friend names (and indirectly a friend count). The two new APIs are taggable_friends and invitable_friends.

In order to make use of the new end-points (or even just to access the user’s friends list), your application must request the user_friends permission. This new permission was introduced as part of Graph API 2.0.

The New Endpoints

Taggable Friends

The taggable_friends API retrieves a list of friends that can be tagged by the user in stories. Not all friends will be displayed, but of the ones that appear, the API will return the a encrypted ID that can be used for tagging, their name and profile photo. The use of this end-point requires login review from Facebook.

Invitable Friends

The invitable_friends API is restricted to games and provides similar functionality to taggable_friends.

Retrieving Taggable Friends

You can retrieve taggable friends using the following code:

See the gist on github.

You can retrieve inevitable friends in a similar way if you have a Game application. Just replace the /taggable_friends in the API call with /invitable_friends.

Using Encrypted ID to Tag Friends

You can use the encrypted IDs from API call to then tag friends in stories (status updates or actions). You must include the place attribute as Facebook only allows friends to be tagged at location. However, if you use a page_id with no address, Facebook hide the location and create a normal status update.

See the gist on github.

The code above creates the following status update on Facebook:

Exit mobile version