Facebook iOS SDK v4.0,获取好友列表

好像Facebook iOS SDK v4.0有很多变化。 我尝试在login后获取用户的好友列表。 我认为这是与FBSDKGraphRequestConnection有关,但我不知道如何使用它。

另外,如果我只想得到正在使用我的应用程序的朋友,Facebook的SDK支持?

任何人都可以举个例子吗? 谢谢!

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]; 

这显示了如何处理响应:

 [[[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"]); } } }]; 

我用下面的代码来获取好友列表

 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]); } }]; 

您可以使用limit keyword.Ex限制朋友的数量:limit = 100