Facebook登录官方示例中使用scope

Using scope in Facebook login official example

我知道有些 Facebook 用户没有电子邮件地址。他们可以使用 phone 号码。无论如何,我无法弄清楚在这个官方JS示例中我应该在代码的哪一部分添加{scope: 'email'}

https://developers.facebook.com/docs/facebook-login/web

FB.login(function(response) {
  // handle the response
}, {scope: 'email'});

它就在文档中,只需向下滚动一下即可。

...或使用箭头函数:

FB.login((response) => {
  // handle the response
}, {scope: 'email'});

授权后,您可以通过此API调用获取电子邮件:

FB.api('/me', {fields: 'name,email'}, (response) => {
    console.log(response.email);
});

我想通了。解决方案是在此处添加 email 参数

function testAPI() {
console.log('Welcome!  Fetching your information.... ');
FB.api('/me?fields=name,email', function(response) {  //<-HERE ?fields=name,email
  console.log('Successful login for: ' + response.name);
  document.getElementById('status').innerHTML =
    'Thanks for logging in, ' + response.name + response.id + response.email +'!';
});

}