如何解决"此人已登录Facebook,但不是您的应用程序" javascript sdk

时间:2016-10-07 07:42:32

标签: facebook facebook-javascript-sdk

我希望我的网站能够在facebook上登录,但我看到了这个错误。

    <script>
  // This is called with the results from from FB.getLoginStatus().
  function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    // for FB.getLoginStatus().
    if (response.status === 'connected') {
      // Logged into your app and Facebook.
      // alert('login fb');
      document.getElementById('login').style.display = 'none';
      document.getElementById('startbtn').style.display = 'block';

      testAPI();
    } else if (response.status === 'not_authorized') {
      // The person is logged into Facebook, but not your app.
      alert('not authorized');

    } else {
      // The person is not logged into Facebook, so we're not sure if
      alert('not login fb');
      document.getElementById('login').style.display = 'block';
      document.getElementById('startbtn').style.display = 'none';
    }
  }

  function checkLoginState() {
    FB.getLoginStatus(function(response) {
      statusChangeCallback(response);
    });
  }

  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'my app id',
    oauth   : true,
    cookie     : true,  // enable cookies to allow the server to access 
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.5' // use graph api version 2.5
  });

</script>

它在我的计算机和其他计算机上工作。但是计算机之一 显示提醒(未授权),无法登录。 我该如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

如果状态为not_authorized,您可以调用facebook的登录视图。试试这个:

if (response.status === 'not_authorized') {
      // The person is logged into Facebook, but not your app.
      console.log('Please log into this app.');
      fbLogin();
    }

  function fbLogin(){
      FB.login(function(response) {
        if (response.authResponse) {
         console.log('Welcome!  Fetching your information.... ');
         FB.api('/me/?fields=picture,name,email', function(response) {
            console.log(response);
           console.log('Successful login for: ' + response.name);
           document.getElementById('status').innerHTML =
             'Thanks for logging in, ' + response.name + '!';

         });
        } else {
         console.log('User cancelled login or did not fully authorize.');
        }
    });

  }