我很难通过 Facebook SDK 获取用户信息。
我正在努力争取生日、工作和教育。
我正在使用这个:
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"education, work, email, id, name, first_name, last_name, birthday, gender"])
该电话不提供教育、工作或生日信息。
我拥有 Facebook 批准的以下权限:
- 用户生日
- 用户教育历史
- 用户工作历史记录
当我尝试在上面的代码示例中使用这些值时,应用程序因不存在的字段而崩溃:
type (User), com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=100, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 100;
"fbtrace_id" = CVy14JLKraa;
message = "(#100) Tried accessing nonexisting field (user_birthday) on node type (User)";
type = OAuthException;
};
};
code = 400;
}}
当我尝试使用带有用户 ID 的图形请求时:
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/\(fbid)", parameters: ["fields":"user_birthday"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in ...
我也遇到同样的错误:
message = "(#100) Tried accessing nonexisting field (user_birthday) on node type (User)";
有什么建议吗?
最佳答案
请按照以下步骤操作。 可能适合你。
#define K_Field @"fields"
#define K_Permission @"email,location, birthday, name, link"
#define K_ID @"id"
#define K_Name @"name"
#define K_DOB @"birthday"
#define K_Email @"email"
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[login
logInWithReadPermissions: @[K_Email]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *user, NSError *error) {
if (error || user.isCancelled) {
NSLog(@"Process error");
} else {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{K_Field: K_Permission}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
//Done login
}
}];
}
}
}];
请确保您使用了正确的关键字 与 facebook official docs 相同
关于ios - 无法获取 Facebook 用户信息(生日、工作、教育程度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41886252/