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

时间:2020-03-11 17:05:30

标签: javascript facebook-login

我以最简单的方式使用Facebook登录,并获得回电响应:

<img>

我将响应记录到控制台,并接收名称和ID,但不接收电子邮件地址。我也如何获取电子邮件?经过研究,它应该默认为默认值,对吗?

2 个答案:

答案 0 :(得分:1)

根据os.Pipe(),这是您的操作方式。

  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 docs。希望能有所帮助:)

答案 1 :(得分:1)

好了,我很困惑,应该在这里

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