繁体   English   中英

Facebook获取朋友列表

[英]Facebook Get friends list

我知道这里已经提出了很多要求,但是我找不到合适的答案。

我正在使用Facebook SDK v3.18

我只想获取用户朋友列表和他们的图片。

到目前为止,我已经尝试过了:

登录:

FBLoginView *loginView =
    [[FBLoginView alloc] initWithReadPermissions:
     @[@"public_profile", @"email", @"user_friends"]];
    // Align the button in the center horizontally
    loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), (self.view.center.y - (loginView.frame.size.height / 2)));
    [self.view addSubview:loginView];

获取用户的朋友列表和他们的图片:

[FBRequestConnection startWithGraphPath:@"/me/friends?fields=name,picture"
                             parameters:nil
                             HTTPMethod:@"GET"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          ) {
                          /* handle the result */
                      }];

但是答案是:

{
    data =     (
    );
    summary =     {
        "total_count" = 1216;
    };
}

和非为我的朋友的名字或图片显示:/

请给我一些启发。

提前致谢!

Facebook SDK页面上 ,/ me / friends看起来只会返回您已登录并被授予对同一应用程序许可的朋友(即您和您的朋友需要允许您的应用程序通过登录使用Facebook)。

您是否在下面尝试过?

FBRequest* friendsRequest = [FBRequest requestWithGraphPath:@"me/friends?fields=name" parameters:nil HTTPMethod:@"GET"];
    [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                  NSDictionary* result,
                                                  NSError *error) {
        NSArray* friends = [result objectForKey:@"data"];
        NSLog(@"Found: %i friends", friends.count);
        for (NSDictionary<FBGraphUser>* friend in friends) {
            NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);

        }
        NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
            return friend.id;
        }];

 }];

编辑:

请检查这篇文章。

Facebook Graph Api v2.0 +-/ me / friends返回空白,或仅返回也使用我的应用程序的朋友

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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