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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…