简体   繁体   中英

Getting the user’s Facebook list of friends

After being able to create a small iOS app that logs in to Facebook. I would like this app to get the user's list of friends.

Though I browsed the internet for a while and tried various approach I did not succeed to get what I wanted.

In the viewDidLoad method I use this code to start with:

loginView = [[FBLoginView alloc] initWithReadPermissions:@[@"user_friends"]];

And then I implement the loginViewFetchedUserInfo: user: method this way:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user
{
    [FBRequestConnection startWithGraphPath:@"/me/friends"
                                 parameters:nil
                                 HTTPMethod:@"GET"
                          completionHandler:^(
                                              FBRequestConnection *connection,
                                              id result,
                                              NSError *error
                                              ) {
                              NSLog(@“Result: %@",result);
                          }];
}

When I execute the app I get this result:

Result: {
    data =     (
    );
    summary =     {
        "total_count" = 267;
    }; }

But what I really want is a list of the friends with their names …etc… All the things I tried for that didn't work. Though I suppose the solution must be simple.

I also used code like this in the method above ….. but with no luck:

NSArray* friends = [result objectForKey:@"data"];

One more point, here https://developers.facebook.com/docs/graph-api/reference/v2.1/user/friends one can read:

This will only return any friends who have used (via Facebook Login) the app making the request.

But the result I get (267) does not match this statement. It (267) is the number of friends the user has on Facebook, which is in fact what I am interested in.

I hope someone has something to say to put me on the right track and make things clearer.

Since Facebook's 2.x SDK upgrade they have tightened up access to information in the "Open Graph API."
Under Permissions That Do Not Require Review

App friends. This optional permission grants your app the ability to read a list of friends who also use your app.

You get automatic access to any friends that already use your app (per its Facebook ID.)
You will have to request Extended Permissions if you want to access the list of all a user's friends. That means going through Facebook's App Review process which can be quite challenging (and annoying.)
Frankly, I am not even sure that it is possible to use the new Open Graph API to get the user's entire friend list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM