2013-05-27 29 views
0

我想從Facebook的SessionLoginSample應用程序的用戶的電子郵件地址獲取用戶的電子郵件。我不確定我在這裏做錯了什麼。我相信這是我獲得電子郵件地址的正確領域。您有什麼方向可以告訴我這將有助於我返回一個簡單的電子郵件嗎?任何援助將不勝感激!謝謝!從Facebook的iOS SessionLoginSample應用

- (void)updateView { 
    // get the app delegate, so that we can reference the session property 
    SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; 
    if (appDelegate.session.isOpen) {   
     // valid account UI is shown whenever the session is open 
     [self.buttonLoginLogout setTitle:@"Log out" forState:UIControlStateNormal];   
     [self.textNoteOrLink setText:[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@", 
           appDelegate.session.accessTokenData.accessToken]]; 

//GET THE USER'S EMAIL ADDRESS HERE   
NSString *emailAddress= [user objectForKey:@"email"];   

     self.labelFirstName.text = [NSString stringWithFormat:@"Email: %@", emailAddress]; 

    } else {   
     // login-needed account UI is shown whenever the session is closed 
     [self.buttonLoginLogout setTitle:@"Log in" forState:UIControlStateNormal];   
     [self.textNoteOrLink setText:@"Login to create a link to fetch account data"];   
    } 
} 
+0

您是否設置了權限? http://stackoverflow.com/questions/15481784/facebook-api-email-permissions – Chris

回答

1

請確定您已經向用戶詢問了是否有權限訪問他的電子郵件地址。這裏是鏈接到文檔:https://developers.facebook.com/docs/reference/login/email-permissions/

使與permissionsns

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email",nil]; 

數組,然後添加權限openActiveSessionWithReadPermissions:方法是這樣的:

[FBSession openActiveSessionWithReadPermissions:permissions 
      allowLoginUI:YES 
     completionHandler:^(FBSession *session, 
          FBSessionState status, 
          NSError *error) { 
      if (error) { 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
              message:error.localizedDescription 
              delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
       [alert show]; 

      } 
     }]; 

這例如使用Facebook SDK for iOS

相關問題