Skip to content

Instantly share code, notes, and snippets.

@yat1ma30
Created August 26, 2013 06:32
Show Gist options
  • Save yat1ma30/6338571 to your computer and use it in GitHub Desktop.
Save yat1ma30/6338571 to your computer and use it in GitHub Desktop.
Tweet数、Like数、はてブ数、をjQueryで取得
/**
* いいね!数を取得
*/
function getLikeCount(url, element) {
$.ajax({
url: 'https://graph.facebook.com/',
dataType: 'jsonp',
data: {
id: url
},
success: function(r) {
element.text(r.shares || 0);
},
error: function() {
element.text(-1);
}
});
}
/**
* tweet数を取得
*/
function getTweetCount(url, element) {
$.ajax({
url: 'http://urls.api.twitter.com/1/urls/count.json',
dataType: 'jsonp',
data: {
url: url
},
success: function(r) {
element.text(r.count || 0);
},
error: function() {
element.text(-1);
}
});
}
/**
* はてブ数を取得
*/
function getHatebuCount(url, element) {
$.ajax({
url: 'http://api.b.st-hatena.com/entry.count?callback=?',
dataType: 'jsonp',
data: {
url: url
},
success: function(r) {
element.text(r || 0);
},
error: function() {
element.text(-1);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment