Search code examples
javascriptfacebookfacebook-graph-apifacebook-share

Can I show a facebook share counter of my website on other website?


Simple question:

I want to show a facebook share counter from site1.com on site2.com

Share count

I think I must to do some changes to data-layout="button_count" . But how to do that?


Solution

  • If you simply want to display the share count send a request to

    http://graph.facebook.com/[URL]
    

    It will respond with a JSON object that you can then parse using JavaScript or PHP.

    If called like: http://graph.facebook.com/http://www.stackoverflow.com it will return:

    {
        "id": "http://www.stackoverflow.com",
        "shares": 36267,
        "comments": 4
    }
    

    Example in PHP

    As the question was tagged PHP as well here's an example:

    $x = json_decode( file_get_contents('http://graph.facebook.com/http://www.stackoverflow.com') );
    print $x->shares; // 36267