[英]Invalid version specified, facebook share plugin error
I want to use the facebook share plugin for the web app I am working on, I only need the basic share button.我想为我正在开发的网络应用程序使用 facebook 共享插件,我只需要基本的共享按钮。 The app uses requirejs for loading javascript, so I followed thehow-to and changed the facebook api url to the one found in code snippets on facebook docs .
该应用程序使用 requirejs 来加载 javascript,因此我按照操作方法将 facebook api url 更改为在 facebook docs上的代码片段中找到的那个。 This doesn't work and the sdk throws error
invalid version specified
.这不起作用,sdk 抛出错误
invalid version specified
。 This is how my files look.这就是我的文件的外观。
main.js
require.config({
shim: {
'facebookshare' : {
exports: 'FB'
}
},
paths: {
'facebookshare': "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0"
}
});
require(['fb']);
fb.js
define(['facebookshare'], function(facebook) {
document.body.innerHTML += '<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button"></div>';
});
What is the best way of including only the facebook share plugin with requirejs?仅包含带有 requirejs 的 facebook 共享插件的最佳方法是什么?
I referred following questions, but none of them provide a concrete solution.我提到了以下问题,但没有一个提供具体的解决方案。 Uncaught error: no version specified and wrong version error .
未捕获的错误:未指定版本和错误版本错误。
I was also getting the following error even when using the standard embed code that Facebook provides .即使使用 Facebook 提供的标准嵌入代码,我也收到以下错误。
Uncaught Error: invalid version specified in sdk.js
未捕获的错误: sdk.js 中指定的版本无效
The first thing to check is that you're including the version number in your FB.init
call:首先要检查的是您在
FB.init
调用中包含了版本号:
FB.init({
appId: 'your-app-id',
xfbml: true,
version: 'v2.8'
});
...was to make a simple tweak and changed the path: ...是进行简单的调整并更改路径:
From: //connect.facebook.net/en_GB/sdk.js
To: //connect.facebook.net/en_GB/all.js
And this fixed the error.这修复了错误。 Unfortunately I have no idea why.
不幸的是,我不知道为什么。 :-(
:-(
Consider including a version
parameter to the src
property as shown below:考虑在
src
属性中包含一个version
参数,如下所示:
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.8"
The default template on Like button for Web is incomplete; Web 的 Like 按钮上的默认模板不完整; upon clicking on the "Get Code" button Facebook will generate you a complete template with the
version
parameter included.单击“获取代码”按钮后,Facebook 将为您生成一个包含
version
参数的完整模板。
Minor heads up, I had to change小提醒,我不得不改变
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1
&
version=v2.8";
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1
&
version=v2.8";
to到
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1
&
version=v2.8";
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1
&
version=v2.8";
I ran into this problem when I was changing my file from HTTP to HTTPS.我在将文件从 HTTP 更改为 HTTPS 时遇到了这个问题。 The reason was the lack of specific "HTTP:" or "HTTPS:" in the following code:
原因是以下代码中缺少特定的“HTTP:”或“HTTPS:”:
<div class="fb-comments" data-width="100%" data-href="//amazingjokes.com/image/2017-03-17/A_good_sign_for_St__Patricks_day" data-num-posts="5"
data-colorscheme="light">
</div>
normally the '//domain.com' copies the scheme we're on, so when you're on htts://example.com a link to '//example2.com' will seen as ' https://example2.com '.通常“//domain.com”会复制我们正在使用的方案,因此当您在 htts://example.com 上时,“ //example2.com ”的链接将显示为“ https://example2”。 com '。 For the 'fb-comments' you'll need to specifically state HTTP or HTTPS for the data-href.
对于“fb-comments”,您需要为 data-href 专门说明 HTTP 或 HTTPS。
Also note that ' https://example.com ' according to facebook is another page than ' http://example.com '.另请注意,根据 facebook,“ https://example.com ” 是“ http://example.com ”以外的另一个页面。 So if you upgrade your site for SSL you will lose all past comments if you change the URL in the social plugins from HTTP to HTTPS... The solution I chose was to use HTTP for all older posts, and HTTPS for everything recent
因此,如果您为 SSL 升级您的网站,如果您将社交插件中的 URL 从 HTTP 更改为 HTTPS,您将丢失所有过去的评论……我选择的解决方案是对所有旧帖子使用 HTTP,对最近的所有帖子使用 HTTPS
There is (or was) an error in the source code on the Facebook Share Button Configurator ! Facebook Share Button Configurator上的源代码中存在(或曾经)错误! page.
页。 If you use the Share Configurator on the page, it should work fine.
如果您使用页面上的共享配置器,它应该可以正常工作。 However there is a code example on the page that says 'Copy & paste the code example to your website...', which is bad code and will result in the button not being visible on your page.
但是,页面上有一个代码示例,上面写着“将代码示例复制并粘贴到您的网站...”,这是错误的代码,会导致按钮在您的页面上不可见。 The javascript console will show 'Error: invalid version specified'.
javascript 控制台将显示“错误:指定的版本无效”。
I opened a ticket with Facebook in June of 2018 regarding this issue.我在 2018 年 6 月就这个问题在 Facebook 开了一张票。 They have acknowledged that it's a problem with the code and promised to fix the code example, but as of June 17, 2018 the bad code is still there on the site.
他们承认这是代码的问题并承诺修复代码示例,但截至 2018 年 6 月 17 日,网站上仍然存在错误代码。
Hope this helps.希望这可以帮助。
I changed the original sdk.js to all.js that resolved my problem :我将原来的 sdk.js 更改为 all.js 解决了我的问题:
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/fr_FR/all.js"></script>
And carefully change your language for me it's french 'fr_FR'
并为我小心地更改您的语言,它是法语“fr_FR”
I took my original script from here : https://developers.facebook.com/docs/plugins/page-plugin/我从这里拿了我的原始脚本: https : //developers.facebook.com/docs/plugins/page-plugin/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.