我使用此代码来准备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的noob。很抱歉,如果我的问题对任何人来说都太简单了,请提前感谢您的回答。
答案 0 :(得分:5)
我有相同的Facebook日志
***FB.getLoginStatus() called before calling FB.init().***
文档加载时我发现
末尾的#xfbml=1
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
发生此错误。删除#xfbml=1
后,没关系!
答案 1 :(得分:0)
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,我必须确保正确定义域。