简体   繁体   English

指定的版本无效,facebook 分享插件错误

[英]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'
});

The now-outdated fix...现在过时的修复...

...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 &amp; version=v2.8"; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1 &amp; 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.

相关问题 facebook javascript sdk检查用户是否为粉丝(错误:指定的版本无效) - facebook javascript sdk check if user is fan (Error: invalid version specified) Facebook社交插件共享按钮 - Facebook social plugin share button Facebook分享按钮和评论插件冲突 - Facebook Share button and comment plugin conflict Facebook共享插件按钮未共享正确的URL - Facebook share plugin button does not share the right url Browserify错误{错误:在解析文件:mypath \\ react-app.js时,“ base”中指定的插件1提供了“ loose”的无效属性。 - Browserify Error { Error: Plugin 1 specified in “base” provided an invalid property of “loose” while parsing file: mypath\react-app.js Facebook share_open_graph错误:“无效的操作链接URL:帖子的操作链接必须是有效的URL。” - Facebook share_open_graph error: “Invalid Action Link URL: The post's action links must be valid URLs.” 错误:“/my dir/node_modules/babel-preset-php/src/index.js”中指定的插件 0 提供了“默认”的无效属性 - Error: Plugin 0 specified in "/my dir/node_modules/babel-preset-php/src/index.js" provided an invalid property of "default" 指定了插件0,提供了“ default”的无效属性(Jest React Native) - Plugin 0 specified, provided an invalid property of “default” (Jest React Native) 在Facebook上分享图片给我错误 - Share Image on facebook giving me error 无法在Facebook上共享.fla文件或其发布的html版本 - Unable to share .fla file or its published html version on facebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM