Access to friends of users through the Facebook API?

Has anyone successfully accessed the user's friend list via the Facebook API?

I wrote code to authenticate users on my site through the OAuth API via Facebook. It works great; I can access public information, likes, interests, actions, etc. I access these data points through the following URL format, where I replace "uid" with a valid identifier (I use uid instead of "me" because "I" does not work as advertised):

https://graph.facebook.com/uid?access_token= ...
https://graph.facebook.com/uid/likes?access_token= ...
https://graph.facebook.com/uid/interests?access_token= ...
https://graph.facebook.com/uid/activities?access_token= ...

However, access to friends just doesn't work. URL

https://graph.facebook.com/uid/friends?access_token= ...

returns the following error:

{ "error": { "type": "OAuthAccessTokenException", "message": "An access token is required to request this resource." } } 

The examples in the graphics API all work, but the access token generated on this page has a different format than mine. I do not know why. I followed their instructions on the tee (and whether it worked for everything else!).

Friends are considered public information , and I double-checked Facebook permissions, so I don’t think the problem is.

+6
facebook oauth facebook-graph-api
source share
4 answers

If a user connects to your application, you can find your friends like this:

  $facebook = new Facebook(array( 'appId' => 'xxxxxxxx', 'secret' => 'xxxxxxx', 'cookie' => true, )); // $session is only != null, when you have the session-cookie, that is set by facebook, after the user logs in $session = $facebook->getSession(); // you dont get a list of friends, but a list, which contains other friendlists $friendsLists = $facebook->api('/me/friends'); foreach ($friendsLists as $friends) { foreach ($friends as $friend) { // do something with the friend, but you only have id and name $id = $friend['id']; $name = $friend['name']; } } 

But you only have access to id and name of friends.

+7
source share

You need to get the access token first. Cm:

Facebook Graph API - getting access tokens

0
source share

Where do you get friends to be publicly available? FAQ that you associate with the states:

Publicly available information includes your name, profile photo, gender and network. This information makes it easy to communicate with friends, family, and other people you know in order to contact you.

I do not see any mention of friends in this paragraph.

0
source share

The error you see means that access_token not sent. It is also likely that /me works for you. It is also likely that as soon as you fix it, friends' connections will appear as you expect.

0
source share

All Articles