FB login callback function not responding if user is already logged in facebook

前端 未结 6 1024
星月不相逢
星月不相逢 2021-02-01 22:51

I am using fb connect using js. This is my code:



        
6条回答
  •  盖世英雄少女心
    2021-02-01 23:21

    When you intialize the FB SDK with status:true it will fetch the login status from the user and store it. From that point on when you make calls to FB.getLoginStatus() it isnt accessing fetching the latest data from FB but is instead referring to the locally stored variables that were set at the point of FB.init() - I think its only refreshed once every 20 mins (see https://github.com/facebook/facebook-js-sdk/commit/5b15174c7c9b9ea669499804d4a4c7d80771b036) - however you can force the refresh by doing this:

    FB.getLoginStatus(function() {...}, /*FORCE*/ true);
    

    This should then fire your auth.login event or you could just pass the handler you defined for that event to FB.getLoginStatus as well.

    Can even go a set further and poll this function like:

    setTimeout(function() {
        FB.getLoginStatus(function() {...}, /*FORCE*/ true);
    }, 10000); // poll every 10 seconds
    

提交回复
热议问题