Search code examples
iosobjective-cfacebook-graph-apifacebook-ios-sdk

Facebook Graph API for friends list returns nil on iOS


I am trying to access my own Facebook friends list through this code and the resulting JSON does not return any data.

FBRequest *request = [FBRequest requestWithGraphPath:@"me/friends" parameters:nil HTTPMethod:@"GET"];

I am settings the permissions like this (i am using PARSE)

[PFFacebookUtils linkUser:[PFUser currentUser] permissions:@[@"user_friends"] block:^(BOOL succeeded, NSError *error)

Am I missing something?


Solution

  • Are you using V2 of the API? Facebook has made a big change recently so that this API call now only returns friends who have used the app that is making the request. In other words, you can't fetch your whole friend list, only friends who are also using the app in question.

    More info here:

    https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends

    You can see the difference between version 1.0 and version 2.0 using the dropdown on the top right of the page.

    If you are using the new 2.0 iOS SDK, FBRequest has an instance method to use a different version of the API for a specific request.

    In this case, before you kick off the request, you can do

    [request overrideVersionPartWith:@"v1.0"];
    

    As stated on the v1.0 page though:

    Once a user has logged into an app using version 2.0 (or later), calling this edge for v1.0 will continue to return the later version's response.

    Basically, in order to make this work, your login method must also be an old one.

    If this is a functionality you need to have, depending on how long you are planning on supporting this app, an easier option might be just to use an older version of the Facebook SDK, at least for the time being. It will be supported for roughly another year, by which point either your requirements may change so you can just update, or Facebook may provide us with an ability to fetch a user's entire friend list again, which is unfortunately pretty unlikely.

    The last version using the old API is 3.13.1.

    There are also some other possible options you may use, depending on what you try trying to do with the friend list. There is a bunch of info in other answers on this site, here is one with a good discussion.

    EDIT

    Simon Cross pointed out a bit of info which I did not know. If your app was created after April 30th, 2014, you can't use the v1.0 API at all, regardless of SDK version or anything else. So basically, this workaround is only for people who were already using the 1.0 API in an app of theirs before April 30th.