在 iOS 8 中无法从 Facebook 获取用户的电子邮件个人信息
Posted
技术标签:
【中文标题】在 iOS 8 中无法从 Facebook 获取用户的电子邮件个人信息【英文标题】:not Getting user's email Personal info from Facebook in iOS 8 【发布时间】:2015-09-09 06:24:58 【问题描述】:在我的应用程序中,我必须实现 facebook 登录。基于我正在进行集成的 facebook 文档,但是当我获取用户信息时,电子邮件部分对我来说是空的。 有人可以告诉我问题出在哪里。 我正在使用此代码
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
//login.loginBehavior = FBSDKLoginBehaviorBrowser;
[login logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
if (error)
// Process error
else if (result.isCancelled)
// Handle cancellations
else
if ([result.grantedPermissions containsObject:@"email"])
NSLog(@"result is:%@",result);
[login logOut]; // Only If you don't want to save the session for current app
];
if ([FBSDKAccessToken currentAccessToken])
NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[[[FBSDKGraphRequest alloc] initWithGraphpath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (!error)
NSLog(@"fetched user:%@ and Email : %@", result,result[@"email"]);
];
出去放这个
fetched user:
id = 970029739773026393591;
name = "jace";
and Email : (null)
FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter
【问题讨论】:
【参考方案1】:Facebook
已升级权限,请这样关注
改变这一行
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
进入
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"]
其他reference
【讨论】:
@PRK -- 兄弟很多【参考方案2】:您必须传递参数email
才能通过 Facebook 获取 user_email:
///Add This line
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
[parameters setValue:@"id,name,email" forKey:@"fields"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters] <--------- This line
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (!error)
【讨论】:
【参考方案3】:你必须得到这样的用户电子邮件
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email", @"user_friends",@"user_birthday"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
if (error)
// Process error
NSLog(@"error is :%@",error);
else if (result.isCancelled)
// Handle cancellations
NSLog(@"error is :%@",error);
else
if ([result.grantedPermissions containsObject:@"email"])
NSLog(@"Login successfull");
[self fetchUserInfo];
];
-(void)fetchUserInfo
if ([FBSDKAccessToken currentAccessToken])
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (!error)
NSLog(@"result : %@",result);
];
【讨论】:
以上是关于在 iOS 8 中无法从 Facebook 获取用户的电子邮件个人信息的主要内容,如果未能解决你的问题,请参考以下文章
无法使用延迟深层链接从 Facebook 实时广告中获取安装引荐来源网址值