调用FB.init()之前调用FB.getLoginStatus()

时间:2022-06-09 18:44:20

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

3 个解决方案

#1


22  

Hi I think you are calling fb.init without passing your application ID. It should be like this

嗨,我认为您在不传递应用程序ID的情况下调用fb.init。它应该是这样的

FB.init({
        appId: "Your API ID",
        status: true,
        cookie: true,
        xfbml: true
});

I hope this will work.

我希望这会奏效。

#2


6  

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'

#3


0  

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',
    });

#1


22  

Hi I think you are calling fb.init without passing your application ID. It should be like this

嗨,我认为您在不传递应用程序ID的情况下调用fb.init。它应该是这样的

FB.init({
        appId: "Your API ID",
        status: true,
        cookie: true,
        xfbml: true
});

I hope this will work.

我希望这会奏效。

#2


6  

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'

#3


0  

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',
    });