Javascript 在调用 FB.init() 之前调用 FB.getLoginStatus()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4509971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FB.getLoginStatus() called before calling FB.init()
提问by christian
I want to check if a user is logged-in in facebook using the Facebook JavaScript JDK and jQuery. But even with a timeout of 10 seconds I get this error message:
我想检查用户是否使用 Facebook JavaScript JDK 和 jQuery 登录到 Facebook。但即使超时 10 秒,我也会收到此错误消息:
FB.getLoginStatus() called before calling FB.init().
在调用 FB.init() 之前调用 FB.getLoginStatus()。
Here is my code:
这是我的代码:
<script type="text/javascript" src="/js/jquery-1.2.3.pack.js" />
<div id="fb-root"></div>
<script src="http://connect.facebook.net/de_DE/all.js"> </script>
<script type="text/javascript">
jQuery('document').ready(
function(){
FB.init({
status : true,
cookie : true,
xfbml : true
});
setTimeout(function(){
FB.getLoginStatus(function(response) {
if (response.session) {
jQuery('div#likeButtonWhatsThisText').remove();
}
});
}, 10000)
}
)
</script>
Any ideas on how to get this work?
关于如何获得这项工作的任何想法?
thanks christian
谢谢基督徒
回答by Awais Qarni
Hi I think you are calling fb.init without passing your application ID. It should be like this
您好,我认为您在调用 fb.init 时没有传递您的应用程序 ID。应该是这样的
FB.init({
appId: "Your API ID",
status: true,
cookie: true,
xfbml: true
});
I hope this will work.
我希望这会奏效。
回答by Mauvis Ledford
Not a pro at this but have you tried:
不是这方面的专业人士,但您是否尝试过:
FB.Event.subscribe('auth.login', yourFunc);
And yourFunc should have one arg (response) where you check:
并且 yourFunc 应该有一个 arg(响应),您可以在其中检查:
response.status == 'connected'
回答by Raji
call the init() function like this, it is working for me.
像这样调用 init() 函数,它对我有用。
FB.init({
appId: 'Your App ID',
cookie: true,
xfbml: true,
version: 'v2.10',
});