-1

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?

focusoft
  • 82
  • 1
  • 10

1 Answers1

3

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
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
  • I just edited my question, please check what I want to show. – focusoft Dec 08 '15 at 16:37
  • @focusoft See the example code I've added to my answer. With this code you can get the current amount of shares and you can output it anywhere and in any format you want. This works similar if you're using Javascript. – insertusernamehere Dec 08 '15 at 16:39