2014-10-01 37 views
2

我使用Facebook的SDK v.3.18.2FBRequest不返回用戶的生日

我只希望用戶的名字,姓氏,電子郵件和出生的日期,我得到一切,除了日期出生

我肯定是做錯了權限?不確定。

下面是一些代碼來幫助你找出我的問題,

[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 protected]"; 
    "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」 或 「生日」

回答

0

你需要與public_profile一起索要"user_birthday"

Facebook的文檔閱讀更多here

公共檔案請求包括

  • ID
  • FIRST_NAME
  • 姓氏
  • 鏈接
  • 性別
  • 區域
  • AGE_RANGE

請注意,你必須讓你的應用程序審覈,如果你要求比默認的公共配置的任何額外的許可。

2
[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

控制檯輸出是:enter image description here

我附示例項目和檢查- (IBAction)loginwithCustomButaction:(id)senderthe project link