Skip to content

Instantly share code, notes, and snippets.

@ihorvorotnov
Last active May 26, 2024 08:13

Revisions

  1. ihorvorotnov revised this gist Mar 9, 2014. 1 changed file with 39 additions and 6 deletions.
    45 changes: 39 additions & 6 deletions get-social-shares
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,66 @@
    /**
    * 2Do: add vk.com and other platforms
    */

    Facebook*:
    https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
    + works, returns shares, likes, comments and total

    Twitter:
    http://urls.api.twitter.com/1/urls/count.json?url=%%URL%%&callback=twttr.receiveCount
    + v1 API but still works

    Reddit:
    http://buttons.reddit.com/button_info.json?url=%%URL%%
    + works

    LinkedIn:
    http://www.linkedin.com/cws/share-count?url=%%URL%%
    http://www.linkedin.com/countserv/count/share?url=%%URL%%&format=json
    + works

    Digg:
    http://widgets.digg.com/buttons/count?url=%%URL%%
    - NOT WORKING!

    Delicious:
    http://feeds.delicious.com/v2/json/urlinfo/data?url=%%URL%%
    + works

    StumbleUpon:
    http://www.stumbleupon.com/services/1.01/badge.getinfo?url=%%URL%%
    + works

    Pinterest:
    http://widgets.pinterest.com/v1/urls/count.json?source=6&url=%%URL%%
    + works

    Vkontakte Shares:
    http://vk.com/share.php?act=count&url=%%URL%%
    + works

    Vkontakte Likes:
    http://suvitruf.ru/2012/06/02/1255/

    Odnoklassniki:
    http://www.odnoklassniki.ru/dk?st.cmd=extOneClickLike&uid=odklocs0&ref=%%URL%%
    + works

    Мой Мир Mail.ru:
    http://connect.mail.ru/share_count?url_list=%%URL%%
    + works

    Google+ counts are retrieved via a JSON-RPC POST call.
    POST URL:
    https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ
    POST Body:
    [{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"%%URL%%","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]
    [{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"%%URL%%","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]

    or:
    https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=%%URL%%
    + shows counter, you can parse html (div#aggregateCount)

    $google_request = file_get_contents('https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url='.$url);
    $plusone_count = preg_replace('/(.*)<div id="aggregateCount" class="t1">(([0-9])*)<\/div>(.*)/is','$2',$google_request);

    Reading:
    http://www.tomanthony.co.uk/blog/google_plus_one_button_seo_count_api/
    http://sergunik.name/?p=799
    http://suvitruf.ru/2012/06/02/1255/

    https://gist.github.com/jonathanmoore/2640302
  2. ihorvorotnov created this gist Feb 21, 2014.
    33 changes: 33 additions & 0 deletions get-social-shares
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    /**
    * 2Do: add vk.com and other platforms
    */

    Facebook*:
    https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json

    Twitter:
    http://urls.api.twitter.com/1/urls/count.json?url=%%URL%%&callback=twttr.receiveCount

    Reddit:
    http://buttons.reddit.com/button_info.json?url=%%URL%%

    LinkedIn:
    http://www.linkedin.com/cws/share-count?url=%%URL%%

    Digg:
    http://widgets.digg.com/buttons/count?url=%%URL%%

    Delicious:
    http://feeds.delicious.com/v2/json/urlinfo/data?url=%%URL%%

    StumbleUpon:
    http://www.stumbleupon.com/services/1.01/badge.getinfo?url=%%URL%%

    Pinterest:
    http://widgets.pinterest.com/v1/urls/count.json?source=6&url=%%URL%%

    Google+ counts are retrieved via a JSON-RPC POST call.
    POST URL:
    https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ
    POST Body:
    [{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"%%URL%%","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]