Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/12810018/fb-getloginstatus-called-before-calling-fb-init

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...