137

I can get the share count of an URL using PHP SDK and using the deprecated rest API, but didn't find a way to get the share counts of an URL using graph API.

Is there any way to find out?

Simha
  • 149
  • 3
  • 9
Ashish Pethkar
  • 1,558
  • 4
  • 12
  • 10
  • Get the solution for you in here http://stackoverflow.com/questions/6137414/how-to-fetch-facebook-likes-share-comments-count-from-an-article – Sakata Gintoki Jun 14 '13 at 14:28
  • Please check answer at here: http://stackoverflow.com/questions/9728279/getting-the-facebook-like-share-count-for-a-given-url/35062056#35062056 – Atif Tariq Jan 28 '16 at 12:54
  • Post August 8th, 2016 (non-deprecated) answer: http://stackoverflow.com/a/39379251/4607317 – budi Oct 17 '16 at 19:45

12 Answers12

271

Here's a list of API links to get your stats:

Facebook: https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
Reddit:http://buttons.reddit.com/button_info.json?url=%%URL%%
LinkedIn: http://www.linkedin.com/countserv/count/share?url=%%URL%%&format=json
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%%

Edit: Removed the Twitter endpoint, since that one has been deprecated.

Edit: Facebook REST API is deprecated

Krzysztof Janiszewski
  • 3,763
  • 3
  • 18
  • 38
chandrajeet
  • 8,833
  • 6
  • 23
  • 15
  • 1
    The linkedin one does not work (gives 403 access denied) – Maxim Krizhanovsky Feb 23 '14 at 15:42
  • 1
    I have fixed the url for linkedin. – Ahmed Mar 18 '14 at 07:25
  • The callback for the twitter URL is a bit of a red herring - it isn't necessary and if you're trying to use json_decode (PHP) to process the data it will fail if its wrapped in a callback. – hobailey Apr 15 '14 at 09:17
  • 1
    And not very convenient link to Vkontakte share counter - https://vk.com/share.php?act=count&index=1&url=%%URL%% – bonbonez Apr 21 '14 at 07:23
  • The count for Google+ can be found (in a slightly more complicated way!) as given in this answer: http://stackoverflow.com/a/13385591/1312282 – hobailey May 07 '14 at 09:13
  • 2
    How much is the API call limit for each request? – StErMi Dec 09 '14 at 16:53
  • @StErMi there *usually* aren't limits for these URLs as they don't require any auth (though the results may be cached). But not all the URLs are "officially" supported, which is important to bear in mind. – William Turrell Apr 07 '15 at 19:59
  • 8
    Hi there ! Thanks for this list. I can't find the documentation for the https://api.facebook.com/method/links.getStats API endpoint. It indeed works but I would like to ensure it's not part of a API version that will be decommissioned soon. Also it is strange that this is available without authentication... Do you see anything about this in the facebook documentation ? It is not part of the graph API... – Żabojad Apr 24 '15 at 16:02
  • Also,can we filter the number of counts for certain period.Like 1 week,1 month,...i need to count for 1 month only,any idea? – Ujjwal Jun 26 '15 at 07:38
  • Seems like twitter is no longer available – michaeltintiuc Aug 01 '16 at 14:16
  • 10
    Facebook link is not working anymore. Use http://graph.facebook.com/?id=http://www.google.com – ste1inbeck Aug 19 '16 at 03:27
  • 8
    @MarkOverride an even more optimized version (less bandwidth) is http://graph.facebook.com/?fields=share&id=http://www.google.com . The problem is that these new endpoints are severely rate-limited and it's very hard to use them in production without encountering said limits. If somebody has a different way to do it please let us know. – Jody Donetti Aug 23 '16 at 20:43
  • @njy can you please help with what is the rate limits of this end point ? https://developers.facebook.com/docs/graph-api/reference/v2.7/url i did not find any doc regarding its limits. – Paresh Balar Aug 25 '16 at 05:42
  • @PareshBalar see here https://developers.facebook.com/docs/graph-api/advanced/rate-limiting – Jody Donetti Aug 26 '16 at 00:59
  • @njy: this url `graph.facebook.com/?fields=share&id=http://www.google.com` does not require any token. it seems open url. how limits will be applied and counted for this ? – Paresh Balar Sep 05 '16 at 13:35
  • @PareshBalar again, here https://developers.facebook.com/docs/graph-api/advanced/rate-limiting . While testing locally on my dev machine it worked very well, but on prod servers I kept receiving a "rate limit" error. – Jody Donetti Sep 05 '16 at 13:41
  • If it helps - the ones that I have tested and are working are available wrapped up in some PHP and JS here: https://github.com/lucep/LucepSiteChecker – Kaiesh Sep 15 '16 at 10:42
200

UPDATE - April '15:

If you want to get the count that is available in the Like button, you should use the engagement field in the og_object object, like so:

https://graph.facebook.com/v2.2/?id=http://www.MY-LINK.com&fields=og_object{engagement}&access_token=<access_token>

Result:

{
  "og_object": {
    "engagement": {
      "count": 93, 
      "social_sentence": "93 people like this."
    }, 
    "id": "801998203216179"
  }, 
  "id": "http://techcrunch.com/2015/04/06/they-should-have-announced-at-420/"
}

It's possible with the Graph API, simply use:

http://graph.facebook.com/?id=YOUR_URL

something like:

http://graph.facebook.com/?id=http://www.google.com

Would return:

{
   "id": "http://www.google.com",
   "shares": 1163912
}

UPDATE: while the above would answer how to get the share count. This number is not equal to the one you see on the Like Button, since that number is the sum of:

  • The number of likes of this URL
  • The number of shares of this URL (this includes copy/pasting a link back to Facebook)
  • The number of likes and comments on stories on Facebook about this URL
  • The number of inbox messages containing this URL as an attachment.

So getting the Like Button number is possible with the Graph API through the fql end-point (the link_stat table):

https://graph.facebook.com/fql?q=SELECT url, normalized_url, share_count, like_count, comment_count, total_count,commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url='http://www.google.com'

total_count is the number that shows in the Like Button.

ifaour
  • 38,035
  • 12
  • 72
  • 79
  • I don't get the share count for certain objects. I know they should have at least one share. – Jan Deinhard Aug 10 '11 at 10:15
  • 1
    @Fair, yes sometimes the number is not correct and it's a bit confusing. You may use the fql table suggested by the other answer, but still...sometimes numbers there is not correct too! – ifaour Aug 10 '11 at 10:40
  • is it possible to take shares of few sites? – Aziz Feb 17 '12 at 08:24
  • i use this all the time – Dap Feb 05 '14 at 21:35
  • is there a call limit per hour? – Andres SK Aug 09 '14 at 15:33
  • oops: Invoke-WebRequest : {"error":{"message":"(#4) Application request limit reached","type":"OAuthException","code":4}} – edelwater Sep 23 '14 at 19:50
  • @ifaour Where is the `engagement` field documented? – Tobi Jun 12 '15 at 11:25
  • @Tobi: [here](https://developers.facebook.com/docs/graph-api/reference/v2.3/url) you go :) – ifaour Jun 12 '15 at 13:31
  • 3
    As [v2.6 doc](https://developers.facebook.com/docs/graph-api/reference/v2.6/url) does not let you get `share_count`, `like_count` and `comment_count`, it seems `fql` and the REST API are still the best options ... **But both `fql` and REST API will no longer be available after 7th August 2016!** Any suggestions? – Daniel García Baena May 27 '16 at 18:05
  • Did this change recently? Now I have to use access token to get the value and it looks like: { "share": { "comment_count": 0, "share_count": 977027 }, "id": "http://www.apple.com" } – LarS Aug 20 '16 at 18:09
  • As @edelwater mentioned, I'm too getting the same error. What to do now since both the methods are not working properly now as mentioned by Daniel? – Himanshu Aggarwal Aug 26 '16 at 10:24
21

You should not use graph api. If you either call:

or

both will return:

{
  "id": "http://www.apple.com",
  "shares": 1146997
}

But the number shown is the sum of:

  • number of likes of this URL
  • number of shares of this URL (this includes copy/pasting a link back to Facebook)
  • number of likes and comments on stories on Facebook about this URL
  • number of inbox messages containing this URL as an attachment.

So you must use FQL.
Look at this answer: How to fetch facebook likes, share, comments count from an article

Community
  • 1
  • 1
freedev
  • 25,946
  • 8
  • 108
  • 125
  • you are absolutely right, by total_shares is sum of comments+likes+shares but the page i requested, shows shares_i_have = total_shares + likes – Aziz Feb 22 '12 at 05:58
14

After August 7, 2016 you can still make your call like this:

http://graph.facebook.com/?id=https://www.apple.com/

but the response format is going to be different: it won't be

{
  "id": "http://www.apple.com",
  "shares": 1146997
}

but instead it will be

{
   "og_object": {
      "id": "388265801869",
      "description": "Get a first look at iPhone 7, Apple Watch Series 2, and the new AirPods \u2014 the future of wireless headphones. Visit the site to learn more.",
      "title": "Apple",
      "type": "website",
      "updated_time": "2016-09-20T08:21:03+0000"
   },
   "share": {
      "comment_count": 1,
      "share_count": 1094227
   },
   "id": "https://www.apple.com"
}

So you will have to process the response like this:

reponse_variable.share.share_count
Giorgio Tempesta
  • 1,816
  • 24
  • 32
8

What I found useful and I found on one link above is this FQL query where you ask for likes, total, share and click count of one link by looking at the link_stat table

https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%22http://google.com%22

That will output something like this:

{
    data: [
        {
             like_count: 3440162,
             total_count: 13226503,
             share_count: 7732740,
             click_count: 265614,
             comment_count: 2053601
         }
    ]
}
  • 2
    As of August 8, 2016, FQL will no longer be available and cannot be queried. To migrate your app, use the API Upgrade Tool to see the Graph API calls you can make instead. – Nguyen Minh Binh Aug 04 '16 at 12:52
7

Check out this gist. It has snippets for how to get the sharing count for the following services:

  • Facebook
  • Twitter
  • Google plus
  • Pinterest
  • LinkedIn
  • StumbledUpon
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
4

The facebook like button does two things that the API does not do. This might create confusion when you compare the two.

  1. If the URL you use in your like button has a redirect the button will actually show the count of the redirect URL versus the count of the URL you are using.

  2. If the page has a og:url property the like button will show the likes of that url instead of the url in the browser.

Hope this helps someone

Roland
  • 41
  • 1
3

Simply type in https://graph.facebook.com/?fields=share&id=https://www.example.com and replace example with your url or page you are looking for.

Example of Google: https://graph.facebook.com/?fields=share&id=https://www.google.com

Nate Beers
  • 1,355
  • 2
  • 13
  • 22
1

Using FQL you could do that:

http://graph.facebook.com/fql?q=SELECT url, total_count FROM link_stat WHERE url='PASTE_YOUR_URL_HERE'
totas
  • 10,288
  • 6
  • 35
  • 32
1

There is a ruby gem for it - SocialShares

Currently it supports following social networks:

  • facebook
  • twitter
  • google plus
  • reddit
  • linkedin
  • pinterest
  • stumbleupon
  • vkontakte
  • mail.ru
  • odnoklassniki

Usage:

:000 > url = 'http://www.apple.com/'
  => "http://www.apple.com/"
:000 > SocialShares.facebook url
  => 394927
:000 > SocialShares.google url
  => 28289
:000 > SocialShares.twitter url
  => 1164675
:000 > SocialShares.all url
  => {:vkontakte=>44, :facebook=>399027, :google=>28346, :twitter=>1836, :mail_ru=>37, :odnoklassniki=>1, :reddit=>2361, :linkedin=>nil, :pinterest=>21011, :stumbleupon=>43035}
:000 > SocialShares.selected url, %w(facebook google linkedin)
  => {:facebook=>394927, :google=>28289, :linkedin=>nil}
:000 > SocialShares.total url, %w(facebook google)
  => 423216
:000 > SocialShares.has_any? url, %w(twitter linkedin)
  => true
Timrael
  • 979
  • 1
  • 6
  • 9
1

You can use the https://graph.facebook.com/v3.0/{Place_your_Page_ID here}/feed?fields=id,shares,share_count&access_token={Place_your_access_token_here} to get the shares count.

Gunta Vaishnavi
  • 419
  • 5
  • 6
1

when i used FQL I found the problem (but it is still problem) the documentation says that the number shown is the sum of:

  • number of likes of this URL
  • number of shares of this URL (this includes copy/pasting a link back to Facebook)
  • number of likes and comments on stories on Facebook about this URL
  • number of inbox messages containing this URL as an attachment.

but on my website the shown number is sum of these 4 counts + number of shares (again)

Aziz
  • 859
  • 6
  • 16