我正在尝试使用Facebook SDK获取朋友列表而没有运气。
这是我使用的代码:
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]);
}
}];
这是我得到的错误:
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;
};
}
使用参数运行相同的内容: nil 有效,但不会返回所有需要的数据。
答案 0 :(得分:1)
使用这些权限进行测试和工作:
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)
{
}];
答案 1 :(得分:0)
在Graph API的v2.0中,调用/ me / friends会返回同时使用该应用的人的朋友。
此外,在v2.0中,您必须向每个用户请求user_friends权限。默认情况下,每次登录都不再包含user_friends。每个用户必须授予user_friends权限才能出现在/ me / friends的响应中。有关更多详细信息,请参阅Facebook升级指南