Invalid version specified, facebook share plugin error

Ajinkya picture Ajinkya · Dec 23, 2014 · Viewed 50.9k times · Source

I want to use the facebook share plugin for the web app I am working on, I only need the basic share button. The app uses requirejs for loading javascript, so I followed the how-to and changed the facebook api url to the one found in code snippets on facebook docs. This doesn't work and the sdk throws error 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?

I referred following questions, but none of them provide a concrete solution. Uncaught error: no version specified and wrong version error.

Answer

Simon East picture Simon East · Feb 18, 2015

I was also getting the following error even when using the standard embed code that Facebook provides.

Uncaught Error: invalid version specified in sdk.js

The first thing to check is that you're including the version number in your FB.init call:

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. :-(