Facebook Javascript SDK: getLoginStatus getting no response

一笑奈何 提交于 2019-12-20 06:00:46

问题


As instructed by this page, I include the SDK snippet into my page, except that since I don't have any Facebook APP and I was just trying to build a custom share button on my page, I leave parameter "app-id" as null. To test if it is up and running, on console I execute

FB.getLoginStatus(function(response){
      console.log(response)
})

while I am logged in FB. However, it returns undefined, which means there is no response. What is wrong? Is this because I didn't assign a "app-id"?


回答1:


It depends on where you're calling getLoginStatus from and in what order. It needs to be inside your fbAsyncInit function:

window.fbAsyncInit = function() {
      FB.init({
          appId      : 'your-app-id',
          xfbml      : true,
          version    : 'v2.4'
      });

      FB.getLoginStatus(function(response){
          console.log(response);
      });
}
(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script', 'facebook-jssdk'));

That should load the SDK, initialize everything, then get your login status.



来源:https://stackoverflow.com/questions/33379941/facebook-javascript-sdk-getloginstatus-getting-no-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!