【问题标题】:not Getting user's email Personal info from Facebook in iOS 8在 iOS 8 中无法从 Facebook 获取用户的电子邮件个人信息
【发布时间】: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

【问题讨论】:

    标签: ios objective-c iphone facebook


    【解决方案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);
                       }
                   }];
      
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2018-08-10
        • 2015-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-25
        • 2018-03-06
        • 1970-01-01
        • 2016-02-06
        相关资源
        最近更新 更多