且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-12-06 15:44:16

简单回答



& status = 0 添加到您的 js.src URL以进行警告消失,即:



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



完整答案



FB.init()$ c如果在散列(#)符号后提供参数,则加载时将由facebook脚本内部调用$ c>。这里 xfbml 被传递,所以 FB.init()被调用。



(源代码: http://connect.facebook.net/fr_CA/all/debug.js



如果未明确提供,则使用init()的默认参数: status arg默认是 true - 这使FB脚本在启动时调用 getLoginStatus()抱怨,因为该函数调用需要一个应用程序ID。



FB社交插件不需要应用程序ID - 它们被渲染为iframe源自facebook.com,所以FB登录状态和cookies可供他们访问。



开发人员社交插件部分生成一个URL,其中包含 xfbml param ,应该使用 status = 0 param IMHO。


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.

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.