我很难通过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)";
有什么建议吗?
答案 0 :(得分:0)
请按照跟进。 可能会为你工作。
#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
相同答案 1 :(得分:0)
可以使用Facebook Graph API收集用户的ID并从Graph API访问中获取公开详细信息:
$fb->get('/me?fields=name,first_name,last_name,email,birthday');