Getting the user’s Facebook list of friends

ぐ巨炮叔叔 提交于 2020-01-05 07:32:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/26394874/getting-the-user-s-facebook-list-of-friends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!