[英]Unable to get friends list on Facebook SDK 4 for iOS
I am trying to get list of friends using Facebook SDK with no luck.我正在尝试使用 Facebook SDK 获取朋友列表,但没有运气。
This is the code I use:这是我使用的代码:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/friends"
parameters:@{@"fields": @"fields=id, first_name, last_name, birthday, gender, picture, devices"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (error == nil) {
NSArray* friends = [result objectForKey:@"data"];
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
This is the error I get:这是我得到的错误:
2016-05-08 00:07:12.610 App2Gift[48103:676830] Failed getting friend list
2016-05-08 00:07:12.610 App2Gift[48103:676830] Error: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=100, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 100;
"fbtrace_id" = "G3OpyiU/JKs";
message = "(#100) Unknown fields: fields=id.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#100) Unknown fields: fields=id., com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0} {
"com.facebook.sdk:FBSDKErrorDeveloperMessageKey" = "(#100) Unknown fields: fields=id.";
"com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey" = 0;
"com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode" = 100;
"com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey" = 400;
"com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey" = {
body = {
error = {
code = 100;
"fbtrace_id" = "G3OpyiU/JKs";
message = "(#100) Unknown fields: fields=id.";
type = OAuthException;
};
};
code = 400;
};
}
Running the same with parameters as: nil works but doesn't give back all the needed data.使用与以下参数相同的方式运行: nil可以工作,但不会返回所有需要的数据。
Tested and working, with these permissions:经过测试和工作,具有以下权限:
loginView.readPermissions = @[@"public_profile", @"email", @"user_friends"];
NSString *path = [NSString stringWithFormat:@"/me/friends"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:path
parameters:@{@"fields": @"id, name, picture, devices"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
}];
In v2.0 of the Graph API, calling /me/friends returns the person's friends who also use the app.在 Graph API v2.0 中,调用 /me/friends 会返回此人的也使用该应用程序的朋友。
In addition, in v2.0, you must request the user_friends permission from each user.此外,在 v2.0 中,您必须向每个用户请求 user_friends 权限。 user_friends is no longer included by default in every login.
user_friends 不再默认包含在每次登录中。 Each user must grant the user_friends permission in order to appear in the response to /me/friends.
每个用户都必须授予 user_friends 权限才能出现在对 /me/friends 的响应中。 See the Facebook upgrade guide for more detailed information
有关更多详细信息,请参阅 Facebook 升级指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.