FB init函数提供错误的版本错误 [英] FB init function gives wrong version error
问题描述
我正在使用Facebook JS sdk,我今天创建了一个新的应用程序。
一切都配置正确。
使用init函数,如:
I'm using the Facebook JS sdk, and I have created a new App today. Everything is configured properly. Using init function like:
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxx', // App ID
status : false,
version: 'v2.0',
cookie : true,
xfbml : false // parse XFBML
});
};
(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/pl_PL/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
但是我有一个错误:
未捕获错误:未使用有效版本调用init
正在尝试其他版本,如:2.1,2.2,但仍然没有运气。
我在这里做错了什么?
but I have an error: "Uncaught Error: init not called with valid version " Was trying also other versions like: 2.1, 2.2 and still no luck. What am I doing wrong here?
推荐答案
**免责声明 - 这纯粹是猜测。似乎已经解决了我的问题。
**Disclaimer - This is purely speculation. Seems to have solved my problem.
我在最近的一个项目中遇到过这个问题。我认为这是一个延迟问题。 Facebook SDK要求页面上有< div id =fb-root>< / div>
。这应该是打开body标签后的第一件事。在此之后,您可能会看到您的初始化代码。
I've had this issue on a recent project. I think this is a latency issue. The Facebook SDK requires that <div id="fb-root"></div>
be on the page. This should be the first thing after the opening body tag. After this, you may see your initialization code.
对我来说,这个问题并不一致。我偶尔会看到这个bug,有时我也不会。因此,我的结论是延迟问题。如果SDK找不到 fb-root
,那么它必须创建一个。在这里,我认为存在延迟问题。
For me, this issue was not consistent. I would occasionally see the bug and sometimes I would not. Thus, my conclusion of it being a latency problem. If the SDK cannot find the fb-root
, then it must create one. Herein, is where I believe the latency issue exists.
尝试在打开正文标记之后,但在 FB.init之前添加它({ });
。
Try adding this just after your opening body tag, but before your FB.init({});
.
<div id="fb-root"></div>
这似乎已经为我解决了这个问题,并希望能够帮助其他人。 v1.0文档讨论<$ c $的原因c> fb-root ,但v2.0文档没有提及该项,可能是因为如果找不到它,init脚本会为你添加它。
This seems to have solved the issue for me and will hopefully help others as well. The v1.0 documentation discusses the reason for fb-root
, but the v2.0 docs make no mention of the item, likely because the init script will add it for you if it does not find it.
这篇关于FB init函数提供错误的版本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!