我正在写一个facebook应用程序,它使用badgeville向玩家奖励积分。有时积分需要奖励时,页面加载,但我也有一些facebook的页面上像一个评论框和喜欢按钮的社交插件。看起来,因为页面正在等待这些内容的加载,所以它没有及时加载badgeville内容,以允许奖励积分的函数正确运行。
有没有什么事件可以用来在facebook完成它的工作后运行函数?我找到了"FB.Canvas.setDoneLoading();“,但不确定如何实现它。
谢谢
发布于 2011-09-25 07:21:15
当然,你可能会有这样的东西:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
oauth : true //enables OAuth 2.0
});
FB.Canvas.setDoneLoading(
function () {
alert("Done loading");
});
};
(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>这将确保在设置和初始化FB函数之前不会调用setDoneLoading()。
发布于 2013-01-06 01:52:17
假设您正在进行服务器端登录,则应使用FB.Event.subscribe。如果你用状态: true初始化FB对象,那么auth.statusChange或auth.authResponseChange事件将在FB对象初始化后触发。
FB.Event.subscribe('auth.statusChange', function(response) {
if(response.status == 'connected') {
runFbInitCriticalCode();
}
});
FB.init({
appId : 'appId',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});https://stackoverflow.com/questions/7516524
复制相似问题