How to detect when facebook's FB.init is complete

后端 未结 12 2336
我寻月下人不归
我寻月下人不归 2020-11-28 01:28

The old JS SDK had a function called FB.ensureInit. The new SDK does not seem to have such function... how can I ensure that I do not make api calls until it is fully initia

12条回答
  •  盖世英雄少女心
    2020-11-28 02:18

    Sometimes fbAsyncInit doesnt work. I dont know why and use this workaround then:

     var interval = window.setInterval(function(){
        if(typeof FB != 'undefined'){
            FB.init({
                appId      : 'your ID',
                cookie     : true,  // enable cookies to allow the server to access// the session
                xfbml      : true,  // parse social plugins on this page
                version    : 'v2.3' // use version 2.3
            });
    
            FB.getLoginStatus(function(response) {
                statusChangeCallback(response);
            });
            clearInterval(interval);
        }
    },100);
    

提交回复
热议问题