Search code examples
javascriptfacebookfacebook-graph-apifacebook-social-plugins

Using Facebook Javascript SDK when embedding the social plugin


I'm using Facebook Social Plugin (Like Box) on my website. I can see that Facebook Javascript SDK has been included on my page as well. Is this now available to me for use? Can I get the number of fans using this sdk for example?


Solution

  • Yes, you just have to call your page ID:

    FB.api('/' + pageId, function( r ) {
      var likes = r.likes
    });
    

    But, you must make sure FB sdk have been loaded before (if it's loaded asynchronously). So, make sure it's loaded by assigning a function to fbAsyncInit:

    window.fbAsyncInit = function () {};
    

    This function will be called once the SDK is loaded.