gpt4 book ai didi

javascript - FB.getLoginStatus 需要在触发前刷新页面

转载 作者:行者123 更新时间:2023-11-29 10:52:13 29 4
gpt4 key购买 nike

我有一个 Facebook 页面选项卡应用程序,在刷新页面后才能正确加载。一个多星期以来,我一直在努力解决这个问题,但我已经无计可施了。

代码如下:



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="https:////connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '***************', // App ID
channelURL : '//www.********.com/**********/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});

// Additional initialization code here
};

// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<script type="text/javascript">
$(document).ready(function(){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//User Logged In
}
else if (response.status === 'not_authorized') {
//Log User Into App
}
else
{
top.location = "http://www.facebook.com";
}
});
});
</script>

就像我说的,如果在 FB.getLoginStatus(function(response) { 之后立即添加类似 alert("Test") 的内容,它不会弹出第一个页面加载,但在页面刷新后加载。

有人可以帮我指明正确的方向吗?

谢谢,弗雷德

最佳答案

首先,您要同步和异步加载 SDK。删除同步线。那么所有与 FB 相关的行都应该在 window.fbAsyncInit 中。在 sdk 完全加载之前,您无法订阅事件。

关于javascript - FB.getLoginStatus 需要在触发前刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071781/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com