我正在尝试检查用户是否已使用我的应用登录,但我收到了
FB.getLoginStatus() called before calling FB.init().
控制台出错。 setSize
似乎有效(虽然不完全是 1,710 高度,但肯定在 1,500 左右)所以我不明白为什么 getLoginStatus()
给出错误。
我还仔细检查了 appID(在下面删除),这绝对是正确的。该脚本包含在 <script src="file.js" type="text/javascript"></script>
中在我的下方 <body>
和 <div id="fb-root"></div>
分区
window.fbAsyncInit = function() {
FB.init({
appId : 'APPID', // App ID
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
});
FB.Canvas.setSize({width: 520, height: 1710});
FB.Canvas.setAutoResize(100);
FB.getLoginStatus(function(response) {
if (response.authResponse) {
// logged in and connected user, someone you know
alert("?");
} else {
// no user session available, someone you dont know
alert("asd");
}
});
};
最佳答案
您需要异步加载 api。尝试删除您的 <script src="connect.facebook.net/en_US/all.js"></script>
并将您的 JS 更新为:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelURL : '//WWW.YOUR_DOMAIN.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
});
//
// All your canvas and getLogin stuff 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>
哦,检查 documentation !
关于javascript - FB.getLoginStatus() 在控制台调用 FB.init() 错误之前调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8048564/