views:

140

answers:

3

Has anybody successfully accessed the list of a user's friends via the Facebook Graph API?

I have written code to authenticate users on my website via Facebook's OAuth API. It works splendidly; I can access public information, likes, interests, activities, etc. I access these data points via the following URL format, where I substitute "uid" with a valid id (I use the uid in place of "me" because "me" doesn't 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, accessing friends simply does not work. The 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 on the Graph API docs all work, yet the access token generated on that page has a different format than mine. I'm not sure why. I've followed their instructions to a tee (and have it working for everything else!).

Friends are considered publicly accessible information, and I've double-checked my Facebook account permissions, so I don't think that's the problem.

A: 

You need to get the access token first. See:

Facebook Graph API — getting access tokens

Sarfraz
I am retrieving the access token. I am using it to retrieve the public profile data, likes, interests and activities. Please let me know how my post can be modified to make that more clear.
thebossman
A: 

Where are you getting that friends are publicly accessible? The FAQ you linked to states:

Publicly available information includes your name, profile picture, gender, and networks. This information makes it easier for friends, family, and other people you know to connect with you.

I see no mention of friends in that paragraph.

ceejayoz
You're right. I intended to link to: http://developers.facebook.com/docs/authentication/permissions"By default, your application can access all public data in a user's profile, including her name, profile picture, gender, and friends."
thebossman
The "by default" implies that you can access this information once the user has authenticated your application. That is, the base permission set (what you get when you request no additional scopes/permissions) includes this information. You still do need an `access_token` to get to it though.
daaku
I see, thank you. It appears the access_token I a receiving from the API is invalid. Not sure why...
thebossman
A: 

The error you're seeing implies the access_token is not being sent. This is also likely why /me does work for you. It's also likely that once you fix that, the friends connections will show up as you expect.

daaku
You may be right. I am following the Facebook documentation to a tee, yet I get an access_token that does not resemble that on the documentation itself. Several people on this blog have commented they have the same problem: http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/
thebossman

related questions