Facebook iOS SDK v4.0, get friends list

泪湿孤枕 提交于 2020-01-04 11:09:53

问题


Seems like Facebook iOS SDK v4.0 has a lot of changes. I try to get a user's friends list after he login. I think it's something to do with FBSDKGraphRequestConnection but I'm not sure how it can be used.

Also, if I only want to get friends who are using my app, does facebook sdk support that?

Can anyone give some examples? Thanks!


回答1:


FBSDKGraphRequest *friendsRequest = 
    [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends"
                                      parameters:parameters];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:friendsRequest
     completionHandler:^(FBSDKGraphRequestConnection *innerConnection, NSDictionary *result, NSError *error) {
         ...
     }];
// start the actual request
[connection start];



回答2:


This shows how to handle the response:

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends" parameters:nil]
 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
     if (!error)
     {
        NSArray * friendList = [result objectForKey:@"data"];
        for (NSDictionary * friend in friendList)
        {
            NSLog(@"Friend id: %@", friend[@"id"]);
            NSLog(@"Friend name: %@", friend[@"name"]);             
        }
    }
}];



回答3:


I used below code to get friend list

self.graphrequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/taggable_friends?limit=100"
                                                 parameters:@{ @"fields":@"id,name,picture.width(100).height(100)"}];
[self.graphrequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if (!error) {
        self.resultsArray = result[@"data"];
        [self.fbTableView reloadData];
        [self.fbTableView setHidden:NO];
    } else {
        NSLog(@"Picker loading error:%@",error.userInfo[FBSDKErrorLocalizedDescriptionKey]);
    }
}];

You can limit the number of friends using limit keyword.Ex: limit=100



来源:https://stackoverflow.com/questions/29422826/facebook-ios-sdk-v4-0-get-friends-list

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