簡體   English   中英

在調用FB.init()之前調用FB.getLoginStatus()。 如何使用Facebook API?

[英]FB.getLoginStatus() called before calling FB.init(). How can I use Facebook API?

我使用以下代碼來准備FaceBook API的用法:

(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));

但是,在文檔加載時,出現以下錯誤:

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

我不明白這則訊息。 我已經用谷歌搜索了這個問題,發現了一些論壇話題,但不幸的是,它們根本沒有幫助。 我決定在此發布有關此問題的問題,因為我對Facebook API不了解,因此無法解決。 對不起,如果我的問題對任何人來說都太簡單了,在此先感謝您的回答。

我有相同的Facebook日志

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

加載文檔時。 我發現#xfbml=1

js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";

犯這個錯誤。 刪除#xfbml=1 ,就可以了!

window.fbAsyncInit = function () {
    // init the FB JS SDK
    FB.init({
        appId: MS.FBAppID, // App ID from the App Dashboard
        //channelUrl: '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
        status: true, // check the login status upon init?
        cookie: true, // set sessions cookies to allow your server to access the session?
        xfbml: true  // parse XFBML tags on this page?
    });

    // Additional initialization code such as adding Event Listeners goes here

};

// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might 
// contain some type checks that are overly strict. 
// Please report such bugs using the bugs tool.
(function (d, debug) {
    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/en_US/all" + (debug ? "/debug" : "") + ".js";
    ref.parentNode.insertBefore(js, ref);
} (document, /*debug*/false));

我必須使用為此應用程序創建的Facebook AppID作為AppID,並且必須確保正確定義了域。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM