旧的JS SDK有一个名为FB.ensureInit的函数。新的SDK似乎没有这样的功能……如何确保在api完全启动之前不进行api调用?
我在每个页面的顶部都包含了这样的内容:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $conf['fb']['appid']; ?>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Canvas.setAutoResize();
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
发布于 2015-06-18 21:43:02
有时fbAsyncInit不能工作。我不知道为什么,然后使用这个变通方法:
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);
https://stackoverflow.com/questions/3548493
复制相似问题