Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

facebook

I've this message in my console

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

My code

<div id="fb-root"></div> <script>         // Load the SDK Asynchronously         (function(d){            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];            if (d.getElementById(id)) {return;}            js = d.createElement('script'); js.id = id; js.async = true;            js.src = \"//connect.facebook.net/fr_FR/all.js#xfbml=1\";            ref.parentNode.insertBefore(js, ref);          }(document)); </script> <div class="fb-like" data-send="false" data-layout="button_count" data-width="100" data-show-faces="false"></div> 

I don't understand why. I've only one call of this facebook like plugin in all my website.

like image 955
Jon Avatar asked Oct 09 '12 23:10

Jon


1 Answers

Short answer

Add &status=0 to your js.src URL to make the warning disappear, ie:

//connect.facebook.net/fr_FR/all.js#xfbml=1&status=0

Full answer

FB.init() will be called internally by the facebook script upon loading if parameters are provided after the hash (#) sign. Here xfbml is passed, so FB.init() is called.

(source code: http://connect.facebook.net/fr_CA/all/debug.js line 8699 at the time of this post)

The default args for init() are used if not explicitly provided: status arg default is true - which makes the FB script call getLoginStatus() at startup, which complains because an app ID is needed for that function call.

FB social plugins doesn't need an app ID - they are rendered into an iframe originating from facebook.com, so FB login status and cookies as accessible to them.

The "Get the Code" wizards in the FB developers Social Plug-ins section generates a URL with the xfbml param, it should be updated with the status=0 param IMHO.

like image 142
Sébastien Trottier Avatar answered Sep 22 '22 16:09

Sébastien Trottier