Search code examples
iosfacebookfacebook-graph-apifacebook-ios-sdk

How to get all the friends of the user in FB using iOS SDK


FaceBook launched new API from version 2.0 and asking users to upgrade to new SDK.
In my iOS application (which is not a game), user signs in using Facebook. In side the application I have an option to show all the FB friends of the user (friends who are not using the application).

I tried the below code which returns the friends who are using the application:

[FBRequestConnection startWithGraphPath:@"/me/friends"
                                 parameters:nil
                                 HTTPMethod:@"GET"
                          completionHandler:^(
                                              FBRequestConnection *connection,
                                              id result,
                                              NSError *error
                                              ) {
                              /* handle the result */
                              NSLog(@"%@", result);
                          }];

And below code is not working in my application, because my app is not a game. As per FB, below code works only for Games.

FBRequest *request =  [FBRequest  requestWithGraphPath:@"me/invitable_friends"
                                                parameters:@{@"fields":@"name,installed,first_name"}
                                                HTTPMethod:@"GET"];

    [request startWithCompletionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error){


        NSLog(@"%@", result);
    }];

Is there any other alternative to fetch the friends of the user?


Solution

  • According to the document, with the new Facebook Graph API 2.0, there is no way to fetch all friends.

    Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app