Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB.getLoginStatus() called before calling FB.init()

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:

FB.getLoginStatus() called before calling FB.init().

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

like image 975
christian Avatar asked Dec 22 '10 14:12

christian


2 Answers

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

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

I hope this will work.

like image 67
Awais Qarni Avatar answered Nov 13 '22 15:11

Awais Qarni


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:

response.status == 'connected'
like image 24
Mauvis Ledford Avatar answered Nov 13 '22 14:11

Mauvis Ledford