2013-08-27 95 views
0

我試圖通過我的應用程序登錄來獲取用戶名,Facebook ID和他們的電子郵件。以下是我的應用程序委託:Facebook iOS SDK有時會爲電子郵件返回空值

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI :(FBSessionStateHandler)handler{ 
    NSArray *permissions = [NSArray arrayWithObjects:@"basic_info", @"email", nil]; 
    return [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:allowLoginUI completionHandler:handler]; 
} 

和我completionHandler代碼和所有在這裏:

void (^fbCompletionHandler)(FBSession *session, FBSessionState state, NSError *error) = ^(FBSession *session, FBSessionState state, NSError *error) { 
    switch (state) { 
     case FBSessionStateOpen: 
      break; 
     case FBSessionStateClosed: 
     case FBSessionStateClosedLoginFailed: 
      [FBSession.activeSession closeAndClearTokenInformation]; 
      break; 
     default: 
      break; 
    } 

    if (error && [FBErrorUtility shouldNotifyUserForError:error]) { 
     NSLog(@"%@", error.localizedDescription); 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:[FBErrorUtility userMessageForError:error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alertView show]; 

    } 

    if (session.isOpen) { 
     [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { 
      if (!error) { 
       [self performLoginOperation:user]; 
      } 
     }]; 
    } 
}; 

,我訪問用戶的電子郵件,像這樣:[user objectForKey:@"email"]。大多數情況下,它可以工作,但是每隔一段時間我就會得到一個nil的價值。我不確定爲什麼因爲我在權限中設置了這麼做?這是否有其他原因?

我試圖鑽進去其他SO帖子,但沒有找到答案:

Facebook SDK email sometimes returns null - Android

Facebook SDK 3.0: how to receive user's e-mail?

PHP SDK 3.1.1 getUser() sometimes return 0

回答

3

我有類似的情況,用戶對象不包含電子郵件作爲迴應。我的情況是用戶的電子郵件地址實際上正在等待驗證。在https://developers.facebook.com/docs/reference/api/user/ Facebook的圖形API文檔,對於電子郵件字段,它說:

注:此字段,如果這也是理由不能,如果沒有有效的電子郵件地址是供用戶

見返回你遇到的問題。

+0

事實上,它說有時不會有效是一個非常重要的解決方案。 – KVISH

相關問題