问题 getLoginStatus始终返回not_authorized


我是使用Facebook SDK开发网站的新手。所以请耐心等待。

下面是我验证我登录Facebook的简单代码。 出于某种原因,我总是得到'not_autherized'回复,即使我是我的应用程序的唯一开发人员。我提供的应用程序编号是正确的。

<!DOCTYPE html>
<html lang="en">
  <head>
  </head>
  <body>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
          // init the FB JS SDK
          FB.init({
              appId      : 'censored app id', // App ID from the app dashboard
              status     : true,              // Check Facebook Login status
              cookies    : true,
              xfbml      : true               // Look for social plugins on the page
          });

          FB.getLoginStatus(checkLoginStatus);
          function checkLoginStatus(response) {
              if (response && response == 'connected') {
                  alert('User is authorized!');
              } else {
                  alert('User not authorized!!!');
              }
          };

          // Additional initialization code such as adding Event Listeners goes here
      };

      // Load the SDK asynchronously
      (function(d, s, id) {
          if (d.getElementById(id)) return;

          var js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js";

          var fjs = d.getElementsByTagName(s)[0];
          fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
    </script>
  </body>
</html>

有什么我忽略的吗?

非常感激 :)


6097
2017-08-03 17:22


起源



答案:


一位朋友帮我解决了这个问题。他非常有帮助地指出了Facebook忽略了记录的内容。 当您创建一个新的Facebook应用程序时,它不会由管理员和开发人员自动授权。授权应用程序是存在于“帐户设置 - >应用程序”列表中的应用程序。如果它不在此列表中,则表示未经授权。

这意味着您需要在代码中的某个位置调用FB.login()以弹出用户授权窗口。

请注意,这应该从一个按钮调用。否则,弹出窗口可能会被阻止。

希望除了我之外,这对别人有帮助。

干杯:)


12
2017-08-05 14:22