FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
login.loginBehavior = FBSDKLoginBehaviorSystemAccount;
[login logInWithReadPermissions:@ [@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error)
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
else if (result.isCancelled)
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
else
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
if ([result.grantedPermissions containsObject:@"email"])
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
}
}
}];
我想获取 FB 用户的电子邮件地址,但从上面的代码中我只获取 ID 和名称。 谁能建议我如何获得电子邮件地址?
最佳答案
无论你想读什么,你都需要传递参数 喜欢
[[[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(@"resultis:%@",result);
}
else
{
NSLog(@"Error %@",error);
}
}];
关于ios - 无法使用适用于 IOS 的 facebook sdk 获取电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31380609/