2012-09-02 90 views
1

我使用facebook sdk api和symfony,在$ user_profile數組中,他可以檢索除電子郵件和生日以外的所有信息。facebook api不檢索電子郵件和生日

 require 'facebook.php'; 
     $app_id = sfConfig::get('app_facebook_app_id'); 
     $app_secret = sfConfig::get('app_facebook_secret_key'); 
     $facebook = new Facebook(array(
      'appId' => $app_id, 
      'secret' => $app_secret, 
      )); 
     $user = $facebook->getUser(); 
     if ($user) { 
       try { 
    $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
     } 
     if ($user) {   
      $location= $user_profile['location']['name']; 
      $gender = $user_profile['gender']; 
      $user_info = array(
       'uid' => $user_profile['id'], 
       'first_name' => $user_profile['first_name'], 
       'last_name' => $user_profile['last_name'], 
       'email' => $user_profile['email'], 
       'birthday' => $user_profile['birthday'], 
       'gender' => $user_profile['gender'], 
      ); 

當我使用print_r($user_profile)它返回:

Array ( 
    [uid] => 100004246655890 
    [first_name] => Ala 
    [last_name] => Hamad 
    [email] => 
    [birthday] => 
    [gender] => male 
) 

電子郵件和生日空。

回答

0

如果您沒有收到這些信息,其中一個原因是因爲用戶配置禁止共享這些信息,而Facebook不會發送警告。

由於配置中的某些用戶禁止共享電子郵件或其他信息。

+0

是從一些用戶檢索電子郵件,但其他一些用戶不 –

3

無處在你的代碼它似乎要請求Permission需要訪問用戶的電子郵件地址或生日

檢查權限doc和確保你請求在你的Authenticationemail權限user_birthday碼。

+1

謝謝你的回答後我搜索瞭如何在代碼中編寫代碼,然後我發現我必須在範圍內請求電子郵件許可。 –

0

我搜索瞭如何編寫代碼,然後我發現我必須在登錄URL範圍內申請通過電子郵件的權限:

$params = array(
    'redirect_uri' => url_for('sfGuardAuth/loginWithFB', true),'scope' => 'email,user_birthday,user_location' 
); 
    $loginUrl = $facebook->getLoginUrl($params); 
相關問題