Facebook SDK 没有 return 来自用户的电子邮件
Facebook SDK doesn't return an email from user
我看到这里有很多关于这个的问题,但是我的问题没有解决方案。我有 PHP 带有 Facebook 登录名的网站,我需要一个电子邮件地址,但 Facebook SDK 没有 return。这是JS代码:
$(function(){
$('.fb_reg_btn').click(function(){
FB.login(function(response){
FB.api('/me?fields=email', function(response) {
window.top.location ="http://redirecturlhere";
});
return false;
});
return false;
});
});
这是 PHP,重定向时:
try {
$accessToken = $helper->getAccessToken();
$response = $fb->get('/me?locale=en_US&fields=name,email,first_name,last_name',
$accessToken->getValue());
$result = $response->getGraphUser();
var_dump($result);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(Facebook\Exceptions\FacebookSDKException $e) {
When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
这是使用 Facebook 的标准登录,它工作正常,除了它没有 return 电子邮件地址,但它 return 其他值,如名字、名字、姓氏、ID。 var_dump 的结果是(已编辑):
object(Facebook\GraphNodes\GraphUser)#37 (1) { ["items":protected]=> array(4) { ["name"]=> string(12) "name edited" ["first_name"]=> string(5) "name edited" ["last_name"]=> string(6) "name edited" ["id"]=> string(17) "numbers" } }
如何获取邮箱地址?
我确定用户有电子邮件,我使用的是相同的代码,但另一个 FB 应用程序用于其他站点,具有 FB 登录名,那里有 returns 和电子邮件。我尝试将 'fields' 更改为 'scope',但结果相同。
您必须在登录过程中的 scope 参数中添加 email
权限。例如:
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
FB.api('/me', {fields: 'email'}, function(response) {
window.top.location = 'http://redirecturlhere';
});
}
}, {scope: 'email'});
来源:http://www.devils-heaven.com/facebook-javascript-sdk-login/
另外,确保电子邮件在 Facebook 上获得批准。
我看到这里有很多关于这个的问题,但是我的问题没有解决方案。我有 PHP 带有 Facebook 登录名的网站,我需要一个电子邮件地址,但 Facebook SDK 没有 return。这是JS代码:
$(function(){
$('.fb_reg_btn').click(function(){
FB.login(function(response){
FB.api('/me?fields=email', function(response) {
window.top.location ="http://redirecturlhere";
});
return false;
});
return false;
});
});
这是 PHP,重定向时:
try {
$accessToken = $helper->getAccessToken();
$response = $fb->get('/me?locale=en_US&fields=name,email,first_name,last_name',
$accessToken->getValue());
$result = $response->getGraphUser();
var_dump($result);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(Facebook\Exceptions\FacebookSDKException $e) {
When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
这是使用 Facebook 的标准登录,它工作正常,除了它没有 return 电子邮件地址,但它 return 其他值,如名字、名字、姓氏、ID。 var_dump 的结果是(已编辑):
object(Facebook\GraphNodes\GraphUser)#37 (1) { ["items":protected]=> array(4) { ["name"]=> string(12) "name edited" ["first_name"]=> string(5) "name edited" ["last_name"]=> string(6) "name edited" ["id"]=> string(17) "numbers" } }
如何获取邮箱地址? 我确定用户有电子邮件,我使用的是相同的代码,但另一个 FB 应用程序用于其他站点,具有 FB 登录名,那里有 returns 和电子邮件。我尝试将 'fields' 更改为 'scope',但结果相同。
您必须在登录过程中的 scope 参数中添加 email
权限。例如:
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
FB.api('/me', {fields: 'email'}, function(response) {
window.top.location = 'http://redirecturlhere';
});
}
}, {scope: 'email'});
来源:http://www.devils-heaven.com/facebook-javascript-sdk-login/
另外,确保电子邮件在 Facebook 上获得批准。