如何使用Facebooksdk在iOS中列出共同的朋友? [英] How to list the mutual friends in iOS using Facebooksdk?

查看:124
本文介绍了如何使用Facebooksdk在iOS中列出共同的朋友?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照图形API,但我得到的响应为

I have followed the graph api but i am getting the response as

context =     {
    id = dXNlcl9jb250ZAXh0OgGQ2NxhPU1adsVlI9wHXlABJbFICZC9PYfcDq57EiAdimkf6Um0P7dgco2lU1qdiM98jXp5hXpZCVkjBeN0DHCROSZAjio6JAD7gmkIZCqTxVp6dNwZD;
};
id = 1306652987;

}

我的代码是



My code is

FBSDKAccessToken *access = [FBSDKAccessToken currentAccessToken];
if (access!=nil)
{
    NSDictionary *params = @{
                             @"fields": @"context.fields(mutual_friends)",
                             };
    /* make the API call */


    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"1306652987"
                                  parameters:params
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        NSLog(@"result %@",result);
        // Handle the result
    }];
}
else
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile", @"email",@"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
 {
     if (error)
     {
         // Process error
     }
     else if (result.isCancelled)
     {
         // Handle cancellations
     }
     else
     {
         ///me/mutualfriends/[OTHER ID]/?fields=name,picture
         NSDictionary *params = @{
                                  @"fields": @"context.fields(mutual_friends)",
                                  };
         /* make the API call */

         FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                       initWithGraphPath:@"1306652987"
                                       parameters:params
                                       HTTPMethod:@"GET"];
         [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                               id result,
                                               NSError *error) {
             NSLog(@"result %@",result);
             // Handle the result
         }];
         if ([result.grantedPermissions containsObject:@"email"])
         {
             NSLog(@"result is:%@",result);
         }
     }
 }];

}

但在图形API资源管理器中,我得到了正确的输出与朋友的姓名和身份和共同的朋友的总数,但我无法在我的代码中获得完整的答复

But in the graph API explorer i am getting the correct output with mutual friends name and id and total count of mutual friends but i can't get the full response in my code

推荐答案

我有同样的问题。我提出使用id / USER_ID代替上下文ID的错误。

I had the same problem. I made the mistake of using the id/user_id instead of the context id.

context =     {
    id = dXNlcl9jb250ZAXh0OgGQ2NxhPU1adsVlI9wHXlABJbFICZC9PYfcDq57EiAdimkf6Um0P7dgco2lU1qdiM98jXp5hXpZCVkjBeN0DHCROSZAjio6JAD7gmkIZCqTxVp6dNwZD;
};
id = 1306652987;

所以应该是(在Swift中)

So it should be (in Swift)

 FBSDKGraphRequest(graphPath: "dXNlcl9jb250ZAXh0OgGQ2NxhPU1adsVlI9wHXlABJbFICZC9PYfcDq57EiAdimkf6Um0P7dgco2lU1qdiM98jXp5hXpZCVkjBeN0DHCROSZAjio6JAD7gmkIZCqTxVp6dNwZD", parameters: nil).startWithCompletionHandler({ (connection, result, error) -> Void in
        if (error == nil){
            //everything works print the user data
            print(result)
        }  else {
            print(error.description)
        }
    })

还有!共同的朋友必须已经登录到应用程序,并给予user_friends的应用程序权限。

ALSO! The mutual friends MUST have had logged in the app AND given the App permission for "user_friends".

所以你的登录应该是这样的:

So your login should look something like this:

 let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
    fbLoginManager.logOut()
    fbLoginManager.logInWithReadPermissions(["email", "user_friends"], fromViewController: self) { (result, error) -> Void in
        if (error == nil){
            let fbloginresult : FBSDKLoginManagerLoginResult = result
            if(fbloginresult.grantedPermissions.contains("email"))
            {
                self.getFBUserData()
            }

        } else {
            print(error.description)
        }
    }

这篇关于如何使用Facebooksdk在iOS中列出共同的朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆