Skip to content

Instantly share code, notes, and snippets.

@youtalk
Created June 21, 2012 14:06
Show Gist options
  • Save youtalk/2965939 to your computer and use it in GitHub Desktop.
Save youtalk/2965939 to your computer and use it in GitHub Desktop.
Get the numbers of Facebook's likes and comments through Graph API
$.getJSON('https://graph.facebook.com/' + location.href, function (json) {
if (json) {
if (json.shares && json.shares > 0) {
$('a#fb-like > span > span.ui-btn-text')
.text($('a#fb-like').text().split(' ')[0] + ' ' + json.shares);
}
if (json.comments && json.comments > 0) {
$('a#fb-comment > span > span.ui-btn-text')
.text($('a#fb-comment').text().split(' ')[0] + ' ' + json.comments);
}
}
});
<div data-role="controlgroup" data-type="horizontal">
<a href="/like" data-role="button" id="fb-like"
data-theme="b" data-icon="facebook" data-rel="dialog">いいね</a>
<a href="/comment" data-role="button" id="fb-comment"
data-theme="b" data-icon="facebook" data-rel="dialog">コメント</a>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment