使用Facebook登录不返回电子邮件ID

时间:2015-12-22 14:10:46

标签: php facebook facebook-graph-api facebook-opengraph

我正在使用以下代码进行Facebook登录。我之前已经实现了相同的代码。它工作正常。但是现在,在尝试使用新项目时,它没有返回电子邮件ID。但是返回,auth_id,名称等等

    <?php

    require 'facebook/facebook.php';
    require 'config/fbconfig.php';
    require 'config/functions.php';

    $facebook = new Facebook(array(
                'appId' => APP_ID,
                'secret' => APP_SECRET,
                ));

    $user = $facebook->getUser();

    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
        if (!empty($user_profile )) {
            # User info ok? Let's print it (Here we will be adding the login and registering routines)

            $username = $user_profile['name'];
            $uid = $user_profile['id'];
             $email = $user_profile['email'];


             print_r($user_profile);
             die();



        } 
    } 

//something else
?>

print_r($user_profile);的输出是:

  

数组([名称] =&gt; Gijo Varghese [id] =&gt; 95431400XXXXXXX)

1 个答案:

答案 0 :(得分:2)

您没有要求提供电子邮件字段,因此当然不会返回:

$user_profile = $facebook->api('/me?fields=name,email');

此外,您需要在授权过程中要求email权限。但由于它之前适用于你,最有可能是声明字段:https://developers.facebook.com/docs/apps/changelog#v2_4