更新
不幸的是,API 1.1 无法计算 Twitter 分享数
参考:intgr/(number) 是分享数,所有回复都在 JSON
脸书
http://graph.facebook.com/?id=http://{URL}
返回:
{
"id": "http://{URL}",
"shares": intgr/(number)
}
推特
http://cdn.api.twitter.com/1/urls/count.json?url=http://{URL}
返回:
{
"count": intgr/(number)
"url":"http:\/\/{URL}\/"
}
v1.1 更新
不支持 count.json 的 Twitter API 1.1 版。因此,不可能撤销推文计数。但是,我发现Tweet Buttons 使用自定义端点来获取这些数字。
这是新的端点
https://cdn.syndication.twitter.com/widgets/tweetbutton/count.json?url={URL}
我不确定 Twitter 是否会关闭这个端点,并在他们正式关闭 v 1.0 时替换它,但它可以工作。
领英
http://www.linkedin.com/countserv/count/share?url=http://{URL&format=json
返回:
{
"count": intgr/(number),
"fCnt": "intgr/(number)",
"fCntPlusOne":"intgr/(number) + 1", // increased by one
"url":"http:\/\/{URL}"
}
使用 jQuery 获取共享计数
参考:对于 Twitter 和 linkdIn,我必须添加 callback才能获得回复
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
更新:
Another Fiddle (returns the total shares across the 3 above)