Search code examples
iosobjective-cfacebook-graph-apisharefacebook-friends

How to list ALL friends using Graph API 3.x version?


I try to login user to my app with the following permissions:

NSArray* permissions = [[NSArray alloc] initWithObjects:@"email", @"read_friendlists", @"user_friends", nil];

After login I don't get "read_friendlists" permission from

[FBRequestConnection startWithGraphPath:@"/me/permissions"....];

request.

I think this is the reason, why I can't get the full friend list.

I tried to get the list with the following methods:

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

AND

FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                              NSDictionary* result,
                                              NSError *error) {
    NSArray* friends = [result objectForKey:@"data"];
    NSLog(@"Found: %i friends", friends.count);
    for (NSDictionary<FBGraphUser>* friendIns in friends) {
        NSLog(@"I have a friend named %@ with id %@", friendIns.name, friendIns.id);
    }
}];

These methods give me the friends, who also use my app, and not the whole friend list. What's wrong with my method(s)? How to get the full friend list from user?


Solution

  • read_friendlists is not for getting friends, but only for getting the lists you created (without any friends in it). It also needs approval from Facebook before you can use it, but it´s definitely not what you want.

    user_friends is for getting access to the friends who authorized your App too, with /me/friends. That would be the appropriate way.

    There is no way to get ALL friends anymore, unless you want to tag friends (taggable_friends) or invite friends to a game on Facebook Canvas (invitable_friends).