Javascript Facebook登录回调返回姓名,但不返回电子邮件地址

Javascript Facebook登录回调返回姓名,但不返回电子邮件地址,javascript,facebook-login,Javascript,Facebook Login,我以最简单的方式使用Facebook登录,并得到回复: <div id="fb-root"></div> <script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0&appId=881911462250499&autoLogAppEvents=1"></script&g

我以最简单的方式使用Facebook登录,并得到回复:

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0&appId=881911462250499&autoLogAppEvents=1"></script>

<script>
window.fbAsyncInit = function() {
FB.getLoginStatus(function(response) {
                   FB.api('/me',  function (response) {
                        console.log(response);
                    });
});

}
</script>

window.fbAsyninit=函数(){
FB.getLoginStatus(函数(响应){
FB.api('/me',函数(响应){
控制台日志(响应);
});
});
}
我将响应记录到控制台并接收名称和id,但不接收电子邮件地址。我怎样才能得到电子邮件呢?在研究它时,它应该默认得到它,我错了吗?

根据,这就是你如何做的

  function statusChangeCallback(response) {  // Called with the results from FB.getLoginStatus().
    console.log('statusChangeCallback');
    console.log(response);                   // The current login status of the person.
    if (response.status === 'connected') {   // Logged into your webpage and Facebook.
      testAPI();  
    } else {                                 // Not logged into your webpage or we are unable to tell.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this webpage.';
    }
  }


  window.fbAsyncInit = function() {
    FB.init({
      appId      : '{app-id}',
      cookie     : true,                     // Enable cookies to allow the server to access the session.
      xfbml      : true,                     // Parse social plugins on this webpage.
      version    : '{api-version}'           // Use this Graph API version for this call.
    });


    FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
      statusChangeCallback(response);        // Returns the login status.
    });
  };



  function testAPI() {                      // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + '!';
    });
  }
您可以通过这种方式检查登录状态

  function checkLoginState() {               // Called when a person is finished with the Login Button.
    FB.getLoginStatus(function(response) {   // See the onlogin handler
      statusChangeCallback(response);
    });
  }
默认情况下,fb只允许基本权限。你需要的是额外的许可,因此你必须这样申请

FB.login(function(response) {
  // handle the response
}, {scope: 'email,user_likes'});
你可以阅读更多关于它的内容。希望有帮助:)

根据,这就是你的做法

  function statusChangeCallback(response) {  // Called with the results from FB.getLoginStatus().
    console.log('statusChangeCallback');
    console.log(response);                   // The current login status of the person.
    if (response.status === 'connected') {   // Logged into your webpage and Facebook.
      testAPI();  
    } else {                                 // Not logged into your webpage or we are unable to tell.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this webpage.';
    }
  }


  window.fbAsyncInit = function() {
    FB.init({
      appId      : '{app-id}',
      cookie     : true,                     // Enable cookies to allow the server to access the session.
      xfbml      : true,                     // Parse social plugins on this webpage.
      version    : '{api-version}'           // Use this Graph API version for this call.
    });


    FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
      statusChangeCallback(response);        // Returns the login status.
    });
  };



  function testAPI() {                      // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + '!';
    });
  }
您可以通过这种方式检查登录状态

  function checkLoginState() {               // Called when a person is finished with the Login Button.
    FB.getLoginStatus(function(response) {   // See the onlogin handler
      statusChangeCallback(response);
    });
  }
默认情况下,fb只允许基本权限。你需要的是额外的许可,因此你必须这样申请

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

你可以阅读更多关于它的内容。希望有帮助:)

好的,我明白了,我很困惑,它应该在这里:

FB.api('/me', { locale: 'tr_TR', fields: 'email,name' }, function (response) {

明白了,我很困惑,应该在这里:

FB.api('/me', { locale: 'tr_TR', fields: 'email,name' }, function (response) {

非常感谢,我也尝试使用FB.login,包括范围,但是我没有在响应中获得email属性。我不明白为什么。提前感谢非常感谢我也尝试使用FB.login,包括范围,但是我没有在响应中获得电子邮件属性。我不明白为什么。提前谢谢你好,你可以把你的答案标记为我猜的正确答案。你好,你可以把你的答案标记为我猜的正确答案。