简体   繁体   English

无法从iOS 8中的Facebook获取用户的电子邮件个人信息

[英]not Getting user's email Personal info from Facebook in iOS 8

In my app i have to implement facebook login .based on the facebook documentation i am doing integration but when i am fetching users info email section is coming null for me . 在我的应用程序中,我必须基于facebook文档实现facebook login。,我正在进行集成,但是当我获取用户信息时,我的电子邮件部分为null。 can some one tell me where is the issue . 有人可以告诉我问题在哪里。 this code i am using 我正在使用的代码

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

}

getting out put this 出去把这个

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

The Facebook has upgraded the permissions, so follow like this Facebook已升级了权限,因此请遵循以下步骤

change this line 改变这条线

 [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]

into

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"}]

additional reference 附加参考

You will have to pass paramenter email to fetch user_email through Facebook: 您将必须通过paramenter 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)
                          {

                          }

you have to get user email like this 你必须得到这样的用户电子邮件

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

        }
    }

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

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