使用 Facebook 登录不返回电子邮件 ID
Login with Facebook not returning Email id
我正在使用以下代码登录 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);
的输出是:
Array ( [name] => Gijo Varghese [id] => 95431400XXXXXXX )
您不要求提供电子邮件字段,因此当然不会返回:
$user_profile = $facebook->api('/me?fields=name,email');
此外,您需要在授权过程中请求email
权限。但是因为它之前对你有用,所以它很可能与声明字段有关:https://developers.facebook.com/docs/apps/changelog#v2_4
我正在使用以下代码登录 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);
的输出是:
Array ( [name] => Gijo Varghese [id] => 95431400XXXXXXX )
您不要求提供电子邮件字段,因此当然不会返回:
$user_profile = $facebook->api('/me?fields=name,email');
此外,您需要在授权过程中请求email
权限。但是因为它之前对你有用,所以它很可能与声明字段有关:https://developers.facebook.com/docs/apps/changelog#v2_4