【问题标题】:Not getting Email and public profile using Facebook 4.4.0 SDK使用 Facebook 4.4.0 SDK 未获取电子邮件和公共个人资料
【发布时间】:2015-09-27 13:10:02
【问题描述】:

我目前正在开发 Facebook SDK 4.4.0。在 4.4.0 版本之前,在 4.3.0 我们收到电子邮件,public_profile 包含以下代码

NSArray *arrFBPermission = [[NSArray alloc]initWithObjects:@"email",@"public_profile", nil];
    [loginUsingFB logInWithReadPermissions:arrFBPermission handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){ 
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error){
                      if (!error){
                          NSString *fnm = [result valueForKey:@"first_name"];
                          NSString *lnm = [result valueForKey:@"last_name"];
                      }
else{
     Nslog("%@", error localizedDescription);
}
                  }];
}

现在在新 SDK(即 4.4.0)中,我没有得到这些值。为什么?我想要来自 Facebook 的电子邮件、名字、姓氏、身份证。

【问题讨论】:

  • 这个编码很好,你在appdelegate中添加了回调URL
  • @Anbu.Karthik 请参考编辑后的代码

标签: ios facebook facebook-graph-api


【解决方案1】:

Facebook 4.4 SDK 有一些细微的变化。 您必须从 Facebook 帐户请求带有 FBSDKGraphRequest 的参数。

在您的代码中,参数中有nil

使用如下参数更新您的代码:

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

如果您想使用自定义按钮登录 Facebook,那么您可以使用以下完整代码:

- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    login.loginBehavior = FBSDKLoginBehaviorBrowser;
    [login logInWithReadPermissions:@[@"email"] 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);
                 [self fetchUserInfo];
                 [login logOut]; // Only If you don't want to save the session for current app
             }
         }
     }];
}
-(void)fetchUserInfo
{
    if ([FBSDKAccessToken currentAccessToken])
    {
        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"resultis:%@",result);

             }
             else
             {
                 NSLog(@"Error %@",error);
             }
         }];
    }
}

我希望它对你有用。

【讨论】:

  • 完美 太棒了...✌?
  • @AppiShinigami 欢迎随时:)
  • 布拉沃先生非常好的答案
  • @NitinGohel 谢谢先生
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-16
  • 2015-10-15
  • 1970-01-01
  • 2011-03-08
  • 2013-12-15
  • 2023-03-25
  • 1970-01-01
相关资源
最近更新 更多