且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在控制台中调用FB.init()错误之前调用FB.getLoginStatus()

更新时间:2023-12-06 15:53:40

您需要异步加载api。尝试删除< script src =connect.facebook.net/en_US/all.js>< / script> 并将您的JS更新为:

You need to load the api asynchronously. Try removing your <script src="connect.facebook.net/en_US/all.js"></script> and updating your JS to:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelURL : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    //
    // All your canvas and getLogin stuff here
    //
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>

哦,检查文档