skip to Main Content

The Facebook API login “quickstart” page says to put the following code in your page:

<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : '{your-app-id}',
            cookie     : true,
            xfbml      : true,
            version    : '{latest-api-version}'
        });
        FB.AppEvents.logPageView();
    };

    (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_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>

App ID is easy, but what on earth is it expecting for {latest-api-version}? I’ve tried both '2.1' and '2' and both values throw “invalid version specified” to the console.

2

Answers


  1. The trick is including v in the version. Some users may also have neglected to remove the {brackets}.

    As of 2021-06-08 the code should look like this:

            version : 'v11.0'
    

    Readers from the future (or the past) can view this table for different versions: https://developers.facebook.com/docs/graph-api/changelog/versions

    Login or Signup to reply.
  2. use: “v5.0”
    NOT “{v5.0}”

    eg:

        FB.init({
            appId      : 'xxxxxxxx',
            cookie     : true,
            xfbml      : true,
            version    : 'v5.0'
        });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search