ios - FBRequest 不返回用户生日
<p><p>我正在使用 Facebook SDK v.3.18.2</p>
<p>我只想要用户的名字、姓氏、电子邮件和<em>出生日期</em>,<strong>我得到了除了出生日期以外的所有内容</strong>。</p>
<p>我肯定做错了权限?不确定。</p>
<p>这里有一些代码可以帮助你找出我的问题,</p>
<pre><code> allowLoginUI:YES completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
// Call the sessionStateChanged:state:error method to handle session state changes
;
}];
// This method will handle ALL the session state changes in the app
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
NSLog(@"Session opened");
if (FBSession.activeSession.isOpen) {
// This is not working though I'm putting it as comment
// [ startWithCompletionHandler:
// ^(FBRequestConnection *connection,
// NSDictionary<FBGraphUser> *user,
// NSError *error) {
// if (!error) {
// NSLog(@"User Info : %@",user);
// }
// }];
[ startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(@"%@",result);
}];
}
return;
}
</code></pre>
<p>这是输出日志:</p>
<pre><code>{
email = "email@domain";
"first_name" = Hemang;
gender = male;
id = someId;
"last_name" = Shah;
link = "https://www.facebook.com/app_scoped_user_id/someId/";
locale = "en_US";
name = "Hemang Shah";
timezone = "5.5";
"updated_time" = "some date and time";
verified = 1;
}
</code></pre>
<p>但是出生日期不见了,我也在我的个人资料中设置了。</p>
<h1>更新:</h1>
<p>尝试使用以下权限<strong>不工作!</strong></p>
<p>"user_birthdate"或
“生日”</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[ startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
}
else
{
// retrive user's details at here as shown below
NSLog(@"FB user first name:%@",user.first_name);
NSLog(@"FB user last name:%@",user.last_name);
NSLog(@"FB user birthday:%@",user.birthday);
NSLog(@"FB user location:%@",user.location); NSLog(@"FB user gender:%@",);
NSLog(@"email id:%@",);
NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
user.location[@"name"]]);
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
;
break;
default:
break;
}
} ];
</code></pre>
<p>需要引用:<a href="https://developers.facebook.com/docs/facebook-login/ios/v2.0#permissions" rel="noreferrer noopener nofollow">use this link</a> </p>
<p>控制台输出为:<img src="/image/0jIcv.png" alt="enter image description here"/> </p>
<p>我附上了示例项目并检查了 <code>- (IBAction)loginwithCustomButaction:(id)sender</code> <a href="https://www.sendspace.com/file/ujrrgp" rel="noreferrer noopener nofollow">the project link</a> </p></p>
<p style="font-size: 20px;">关于ios - FBRequest 不返回用户生日,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26139090/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26139090/
</a>
</p>
页:
[1]