facebook api没有';t检索电子邮件和生日

facebook api没有';t检索电子邮件和生日,facebook,facebook-graph-api,symfony1,facebook-login,Facebook,Facebook Graph Api,Symfony1,Facebook Login,我将facebook sdk api与symfony一起使用,在下面的$user_配置文件数组中,他可以检索除电子邮件和生日之外的所有信息 require 'facebook.php'; $app_id = sfConfig::get('app_facebook_app_id'); $app_secret = sfConfig::get('app_facebook_secret_key'); $facebook = new Face

我将facebook sdk api与symfony一起使用,在下面的$user_配置文件数组中,他可以检索除电子邮件和生日之外的所有信息

        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\u profile)
时,它返回:

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

电子邮件和生日邮件都是空的。

如果您没有收到这些信息,其中一个原因是用户配置禁止共享这些信息,而Facebook不发送警告


因为配置中的某些用户禁止共享电子邮件或其他信息。

您的代码中没有任何地方显示您请求访问用户电子邮件地址或生日所需的信息


检查权限文档,确保您在代码中请求了
电子邮件
用户生日
权限。

我搜索了如何在代码中写入权限,然后发现我必须在登录url的范围内请求电子邮件权限:

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

是的,它从一些用户那里检索电子邮件,但其他一些用户不感谢您在您的回答之后,我搜索了如何在代码中编写,然后我发现我必须在范围内请求电子邮件权限。