简体   繁体   English

无法使用iOS的Facebook SDK获取电子邮件地址

[英]Can't get email address using facebook sdk for IOS

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);
                     }
                 }];
            }
        }
    }
}];

I want to get email address for FB user, But from above code I'm just getting id and name only. 我想获取FB用户的电子邮件地址,但是从上面的代码中,我仅获得ID和名称。 Can anyone please suggest me how can I get email address? 谁能建议我如何获得电子邮件地址?

you need to pass perameter whatever u want to read Like 你想读的东西都需要通过perameter

[[[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);
         }
     }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM