【问题标题】:FBRequest not returning user birthdateFBRequest 不返回用户生日
【发布时间】:2014-10-01 10:17:30
【问题描述】:

我正在使用 Facebook SDK v.3.18.2

我只想要用户的名字、姓氏、电子邮件和出生日期我得到了除了出生日期以外的所有内容

我肯定做错了权限?不确定。

这里有一些代码可以帮助你找出我的问题,

    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"] allowLoginUI:YES completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
         // Call the sessionStateChanged:state:error method to handle session state changes
         [self sessionStateChanged:session state:state error:error];
     }];

// This method will handle ALL the session state changes in the app
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError     *)error
{
    // If the session was opened successfully
    if (!error && state == FBSessionStateOpen){
        NSLog(@"Session opened");
        if (FBSession.activeSession.isOpen) {

//            This is not working though I'm putting it as comment
//            [[FBRequest requestForMe] startWithCompletionHandler:
//             ^(FBRequestConnection *connection,
//               NSDictionary<FBGraphUser> *user,
//               NSError *error) {
//                 if (!error) {
//                     NSLog(@"User Info : %@",user);
//                 }
//             }];
        
        [[FBRequest requestForGraphPath:@"me"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            NSLog(@"%@",result);
        }];
    }
    return;
}

这是输出日志:

{
    email = "email@domain";
    "first_name" = Hemang;
    gender = male;
    id = someId;
    "last_name" = Shah;
    link = "https://www.facebook.com/app_scoped_user_id/someId/";
    locale = "en_US";
    name = "Hemang Shah";
    timezone = "5.5";
    "updated_time" = "some date and time";
    verified = 1;
}

但是出生日期不见了,我也在我的个人资料中设置了。

更新:

尝试使用以下权限不工作!

"user_birthdate" 或 “生日”

【问题讨论】:

    标签: ios objective-c facebook-ios-sdk userinfo


    【解决方案1】:
     [FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_birthday",@"public_profile"]
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
    
                                      switch (state) {
                                          case FBSessionStateOpen:
                                              [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                                                  if (error) {
    
                                                      NSLog(@"error:%@",error);
    
    
                                                  }
                                                  else
                                                  {
                                                      // retrive user's details at here as shown below
                                                      NSLog(@"FB user first name:%@",user.first_name);
                                                      NSLog(@"FB user last name:%@",user.last_name);
                                                      NSLog(@"FB user birthday:%@",user.birthday);
                                                      NSLog(@"FB user location:%@",user.location);                                                      NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
                                                      NSLog(@"email id:%@",[user objectForKey:@"email"]);
                                                      NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
                                                                             user.location[@"name"]]);
    
                                                  }
                                              }];
                                              break;
    
                                          case FBSessionStateClosed:
                                          case FBSessionStateClosedLoginFailed:
                                              [FBSession.activeSession closeAndClearTokenInformation];
                                              break;
    
                                          default:
                                              break;
                                      }
    
                                  } ];
    

    需要参考:use this link

    控制台输出为:

    我附上了示例项目并检查- (IBAction)loginwithCustomButaction:(id)senderthe project link

    【讨论】:

      【解决方案2】:

      您需要询问"user_birthday"public_profile

      在 facebook 文档中阅读更多 here

      公开个人资料请求涵盖

      • 身份证
      • 姓名
      • 名字
      • 姓氏
      • 链接
      • 性别
      • 语言环境
      • 年龄范围

      请注意,如果您要求获得除默认公开个人资料之外的任何额外权限,则必须让您的应用得到审核。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-30
        • 2021-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-03
        相关资源
        最近更新 更多