如何从Facebook图形API返回电子邮件

How to get email returned from Facebook Graph API?

本文关键字:API 返回 电子邮件 图形 Facebook      更新时间:2023-09-26

我正在使用Facebook SDK来实现登录。

// Here we run a very simple test of the Graph API after login is
// successful.  See statusChangeCallback() for when this call is made.
function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      console.log(response);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + response.email + response.id + '!';
    });
    FB.api('/me/permissions', function(response) {
      console.log(response);
    });
}
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>

登录成功,上面的代码显示用户的名称和id。然而,电子邮件显示为未定义。这很奇怪,因为当我检查为权限查询返回的响应对象时,我看到user_friends、电子邮件和public_profile都被授予了权限。为什么电子邮件没有定义?

一些可能的原因:

账户上没有电子邮件地址

账户上没有确认的电子邮件地址

账户上没有经过验证的电子邮件地址