Create a gist now

Instantly share code, notes, and snippets.

Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.








   "id": "",
   "shares": 61




({"count": 0, "url": ""})





Google Plus


POST body:



    "result": { 
        "kind": "pos#plusones", 
        "id": "", 
        "isSetByViewer": false, 
        "metadata": {
            "type": "URL", 
            "globalCounts": {
                "count": 3097.0
    } ,
    "id": "p"




        "title":"Style Hatch - Hand Crafted Digital Goods",

Awesome stuff man!

But, at Sevenly, we've found a better way to count the real total shares on Facebook. It's much more complicated, but far more accurate.

Using FB Query for a specific URL only,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%22

At Sevenly, we use this url to get the current total shares for the unique URL for this week's campaign. This helps us include comments, shares, and likes in the count.

The Result

   "data": [
         "like_count": 757,
         "total_count": 1587,
         "share_count": 680,
         "click_count": 0,
         "comment_count": 150

Using the Graph API to get all domain mentions

It's complicated because you have to to go through each page of results and add them up. BUT, this is far more accurate, as it counts the total times your domain was not only shared from the page, but shared once it made it's way onto Facebook.

The Results

   "data": [
         "id": "10150605670960507/insights/domain_stories/day",
         "name": "domain_stories",
         "period": "day",
         "values": [
               "value": 142,
               "end_time": "2012-01-30T08:00:00+0000"
               "value": 355,
               "end_time": "2012-01-31T08:00:00+0000"
               "value": 237,
               "end_time": "2012-02-01T08:00:00+0000"
               "value": 159,
               "end_time": "2012-02-02T08:00:00+0000"
               "value": 193,
               "end_time": "2012-02-03T08:00:00+0000"
               "value": 137,
               "end_time": "2012-02-04T08:00:00+0000"
               "value": 114,
               "end_time": "2012-02-05T08:00:00+0000"
               "value": 73,
               "end_time": "2012-02-06T08:00:00+0000"
               "value": 813,
               "end_time": "2012-02-07T08:00:00+0000"
               "value": 463,
               "end_time": "2012-02-08T08:00:00+0000"
               "value": 376,
               "end_time": "2012-02-09T08:00:00+0000"
               "value": 260,
               "end_time": "2012-02-10T08:00:00+0000"
               "value": 192,
               "end_time": "2012-02-11T08:00:00+0000"
               "value": 287,
               "end_time": "2012-02-12T08:00:00+0000"
               "value": 234,
               "end_time": "2012-02-13T08:00:00+0000"
               "value": 356,
               "end_time": "2012-02-14T08:00:00+0000"
               "value": 155,
               "end_time": "2012-02-15T08:00:00+0000"
               "value": 133,
               "end_time": "2012-02-16T08:00:00+0000"
               "value": 96,
               "end_time": "2012-02-17T08:00:00+0000"
               "value": 132,
               "end_time": "2012-02-18T08:00:00+0000"
               "value": 80,
               "end_time": "2012-02-19T08:00:00+0000"
               "value": 123,
               "end_time": "2012-02-20T08:00:00+0000"
               "value": 723,
               "end_time": "2012-02-21T08:00:00+0000"
               "value": 442,
               "end_time": "2012-02-22T08:00:00+0000"
               "value": 288,
               "end_time": "2012-02-23T08:00:00+0000"
               "value": 286,
               "end_time": "2012-02-24T08:00:00+0000"
               "value": 349,
               "end_time": "2012-02-25T08:00:00+0000"
               "value": 158,
               "end_time": "2012-02-26T08:00:00+0000"
               "value": 110,
               "end_time": "2012-02-27T08:00:00+0000"
         "title": "Daily Total Actions",
         "description": "Daily The number of times people posted a link to your site through an action on a social plugin or through a status message or Wall post. (Total Count)"
   "paging": {
      "previous": "",
      "next": ""

AND, It's an awesome daily breakdown. Perfect for analytics junkies!


Insanely useful - thanks!


Amazing - thanks


hello there, there's a new way to get the different social counts, check this link the code was so handy and useful, you can also use it as much as you want. Sparky!


Excellent collection. Here is a complete and evolving list of apis to fetch social counts with examples:


This is for wordpress users. Here is a well structured and responsive plugin to display social trends on your wordpress site:

This plugin mainly uses these social apis to show the counts with a uniform design across the browsers.


Awesome share, thank you. I've built a PHP wrapper around this and included support for a few additional services. It's available for your forking pleasure here.


I'm guessing this twitter api is going to be effected by this:


If I make a server side request from a Heroku Dyno, pinterest returns a 403 response. Anybody else have this issue?


Twitter ignores query strings. So for example, If I am looking for a share count for a youtube video .

API Call

JSON Response


Makes perfect sense as anything after & unencoded will assume another parameter other than url.

So I encode the URL but even then it seems like it ignores some query params.

API Call

JSON Response


The JSON response swallows the "feature=relmfu" parameter altogether. Facebook does not have this issue.


Here's a method for getting Google+ counts without an api key:$URL_ENCODED_URL&count=true

it returns json. The following regex will get you the count: /c: ([0-9.]+) /


where i can get API_KEY?


Hello, nyquildotorg mentioned that the url can return json, I'm trying to figure out how to make it return json but no such luck. Can someone go into a bit more detail on how to get that url to return json?


Pinterest complains that the callback= is null on your example.


The Facebook graph call can also work with multiple urls at once. Using the parameter “ids” instead of “id” allows a list of comma separated urls.[first url],[second url],[third urls]

The result looks returns an object with the url as the key.,,,,

Response returned by Facebook graph api is:

"": {
"id": "",
"shares": 25
"": {
"id": ""
"": {
"id": ""
"": {
"id": "",
"shares": 12
"": {
"id": ""


@texaswebguy , I changed callback= to callback" and it worked for me.
example :


this is so good. i thank you.


This is very good.


Cheers to @evansims for his initial work. I recently forked and refactored his script to provide a nice OO PHP SocialWorth class. It allows you to easily query multiple URLs and set which networks you want to query.


Check out the following for Google+ count.


good ~!


Another option to check g+:

Not a JSON output, but works if you need a quick check.


Any idea for disqus?


This has been really helpful.

Here's a solution for checking Google+ in Rails without an API key. It opens a fastbutton page and uses Nokogiri to parse it and return the share count.


Will Guzzle make this faster than using cURL?


@aligajani No, because Guzzle likely uses cURL.


Really helpful, it save my day.


This is great! I'm having a little trouble getting the Google+ count however.

A linked to article which has an API key put in already works fine but when I substitute that for my own API Key - I get a 0 share count return for the same URL.

I've enabled the Google+ API in my Developers Console, what else am I missing?


@0Neji I think the G+ method is deprecated. This worked for me


Here is another solution. All counters including G+ works correctly.


People like you make the Internet a better place.


Great guide. I made a ruby gem according this info:
I hope it will help you <3


Any ideas for XING?


Hey @jonathanmoore, are you still around to update this?

  • The LinkedIn API doesn't work if called directly from the client; you need a JSONP callback.
  • Google Plus without authentication is possible:

    function GooglePlus(url) {
    // bypass same-origin restriction
      jQuery.getJSON('' + encodeURIComponent('' + url), function (data){
      alert(data.contents.match(/{c: (\d+)/)[1]);

Thanks.. but i always get (#4) Application request limit reached on facebook graph api.


Is there a way to just get the share count by not sending multiple requests with http or https and www in Twitter and Pinterest?

Because I've checked and confirmed, that Twitter and Pinterest indeed differentiate between http,https and www links.

So, for a link like this:,
I'd have to check for

Because users on my site could either access it as http or https and with or without www.


Very good, and thanks a lot. And I want to ask, is it possible to get the Pocket marked number?


"NetworkError: 415 Unsupported Media Type". I can't even test lol


Any one can help me please....!!
i need a code for

Get details of users/visitors who share our URL on Facebook, Twitter.

i need a list of peoples who share our link on facebook and twitter.


Cool stuff man!

Anyone figured out / found how to get share count from Xing ?


Maybe you want to get stars and watch for Github?


For faster results from Pinterest, please use and not Like so:

Encoding your URL parameter is a good habit to learn; if you need to send one with a question mark in it, unpredictable things may happen.

Callback is not a required parameter; if you omit, your reply will look like this:


As noted previously, URLs are not normalized for count.json. You'll get a much higher count from laughingsquid by appending a forward-slash to the URL, like so:


Google plus do not need KEY


For those who cannot do AJAX request on Twitter, I posted a really raw solution on SO Hope it can help.



I try get share count from StumbleUpon on my site:

$.getJSON('' + encodeURIComponent('') + '&callback=?', function(response) {
  var getResult = 'result';
  for (var getResult in response) {
    if (response.hasOwnProperty(getResult)) {
      var count = response.getResult.views;

But Chrome console show me error message:

Uncaught SyntaxError: Unexpected token :

Also I try this code:

$.getJSON('' + encodeURIComponent('') + '&callback=?', function(response) {

But this error still in console..

Any ideas? Help me please, if you can!


Good info


Awesome. Thanks!


Very helpful, Thanks.


On September 22nd, Twitter announced that, at some point within a month, they would discontinue the Tweet share count API endpoint. This means the endpoint will stop working.

See the official announcement here:


@lutsen this docs will not work without anonym calls but what we do to get share count?


@enjoyiacm have you found any solution?


@younes0 nope.. but still founding..


@enjoyiacm At this point, there seems to be no anonymous solution. You have to use an API key.


Is there any way to handle urls protocol agnostic?


Not as savvy as everyone else here, I am looking to pull share counts for URLs in excel. Is this possible?


As per @lutsen's comment above, the Twitter Count API is scheduled to stop working after today (20th Nov 2015).


Yep. API 1.0 and share count not working.. RIP twitter share counters of all world..


So there is no way to get the twitter share counter via API? Why? :/ If someone see a alternative or a workaround please reply, thanks!


@voku it's not the best solution, but i did make an ajax request every time when user click on my custom tweet button and store in the database. Of couse, it's not 100% perfect, because user can close the window without share, but better then nothing. :)


@voku @enjoyiacm @Methos21 @lutsen Try to get Twitter share counts. You need to sign-up using your Twitter account, add the sites you wish to track (up to 1000), and then use to get the counts.

@pagelab it's another way to grab counts from Twitter.


Here is another gem built for this purpose. It was constructed several years ago but has recently been updated to remove stale API endpoints and add new ones.


+1 @kenbrew


+1 @mindtonic, how can we use it in PHP?


Twitter is broken.




Anyone know of a Facebook (fql) alternative? Point me in the right direction


the FB share counts and the subscriber count is not working anymore. does anyone know an alternative for it


@timdmaxey & @shavini. When you get the data via the Graph API, for example it returns an object.
To get the share count, you need to return $data->share->share_count;.


anyone here knows share count for the ff:




Thanks OP for the effort. These are handful resource.
To reply some queries posed some some readers, twitter count is never complete nowadays. Twitter doesnt provide total share count, so even those third party share counters who claim to keep the record of tweets of their own also can only track partially (because they too need to scrape data using twitter incomplete api)

There is one social signal counter I found most complete is by called SocialCounter.
They show 30 different share counts and they are pretty accurate. Although they dont offer api support.
Here is the link if it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment