Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook, Twitter, LinkedIn share link count

Tags:

Is there any way to get the number of users to share a link on Facebook, Twitter, and LinkedIn?

Example: How many times some link was shared to Facebook, Twitter, and LinkedIn to calculate the popularity of some content?

How to get share count my particular API? Is there any other option? Is there some API?

like image 802
Sajith Avatar asked Jan 09 '14 05:01

Sajith


People also ask

How can you tell how many times a link has been shared?

The good news is you can easily see how many times a page has been shared on social media platforms by using Shared Count. You can paste any url into Shared Count and it will show you how the article has been shared across Facebook, LinkedIn, Twitter, Google+, Delicious, StumbleUpon and Pinterest.


1 Answers

Update

Unfortunately, Twitter share count is impossible with API 1.1

Ref: intgr/(number) is number of shares and all responses are in JSON

Facebook

http://graph.facebook.com/?id=http://{URL} 

Returns:

{    "id": "http://{URL}",    "shares": intgr/(number) } 

Twitter

http://cdn.api.twitter.com/1/urls/count.json?url=http://{URL} 

Returns:

{      "count": intgr/(number)    "url":"http:\/\/{URL}\/" } 

v1.1 Update

Version 1.1 of Twitter API which does not support count.json. Thus, it will not be possible to retireve tweets counts. However, I figured out that Tweet Buttons use a custom endpoint to get these numbers.

Here's the new endpoint

https://cdn.syndication.twitter.com/widgets/tweetbutton/count.json?url={URL} 

I am not sure whether Twitter will take this endpoint down, and replace it when they officially shutdown v 1.0, but it works.

LinkedIn

http://www.linkedin.com/countserv/count/share?url=http://{URL&format=json 

Returns:

{    "count": intgr/(number),    "fCnt": "intgr/(number)",    "fCntPlusOne":"intgr/(number) + 1", // increased by one    "url":"http:\/\/{URL}" } 

Getting shares count with jQuery

Ref: for Twitter and linkdIn I had to add callback to get a response

HTML:

<p id="facebook-count"></p> <p id="twitter-count"></p> <p id="linkdin-count"></p> 

JS:

$('#getJSON').click( function () {      $('#data-tab').fadeOut();     $URL = $('#urlInput').val();      // Facebook Shares Count     $.getJSON( 'http://graph.facebook.com/?id=' + $URL, function( fbdata ) {         $('#facebook-count').text( 'The URL has ' + ReplaceNumberWithCommas(fbdata.shares) + ' shares count on Facebook')     });      // Twitter Shares Count     $.getJSON( 'http://cdn.api.twitter.com/1/urls/count.json?url=' + $URL + '&callback=?', function( twitdata ) {         $('#twitter-count').text( 'The URL has ' + ReplaceNumberWithCommas(twitdata.count) + ' shares count on Twitter')     });      // LinkIn Shares Count     $.getJSON( 'http://www.linkedin.com/countserv/count/share?url=' + $URL + '&callback=?', function( linkdindata ) {         $('#linkdin-count').text( 'The URL has ' + ReplaceNumberWithCommas(linkdindata.count) + ' shares count on linkdIn')     });      $('#data-tab').fadeIn();  }); 

Complete Fiddle

UPDATE:

Another Fiddle (returns the total shares across the 3 above)

like image 157
Adam Azad Avatar answered Sep 20 '22 15:09

Adam Azad