如何使用FBSDKGraphRequest获取Facebook好友列表

时间:2017-01-20 10:36:00

标签: objective-c facebook facebook-graph-api

我在响应中获得总计数,但数据为空。任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

您可以在请求user_friends权限并运行以下代码后检索用户朋友列表,这将返回每个朋友的uid

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{user-id}/friends"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

要获取特定朋友列表中的朋友,您需要请求权限read_custom_friendlists并使用从/{user-id}/friendlists边缘返回的friendw列表ID运行以下代码

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{friend-list-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];