如何使用Facebooksdk在iOS中列出共同的朋友?

我已经按照图表API,但我得到的答复

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

}

我的代码是

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

但在graphicsAPI浏览器中我得到了共同的朋友的名字和身份证和共同的朋友总数正确的输出,但我不能在我的代码中得到完整的回应

我有同样的问题。 我犯了使用id / user_id而不是上下文ID的错误。

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

所以它应该(在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) } }) 

也! 共同朋友必须已经login的应用程序,并给予“user_friends”应用程序的权限。

所以你的login应该是这样的:

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