In my last post I'd shared in detailed post on Facebook comment box. When their is comment box then their is comment count. Every good blog shows the number of comments on each post. I'm going to share a easy-to-use method get comment counts. We are going to use jQuery's $.getJSON() function and Facebook graph API.
Like we pulled out data from Facebook using jQuery we have to do the same but the change will be that we are going to take comments count this time. Facebook stores every comment and shares for each link in their database, if their is any comment present then the JSON path for that comment will be (taking data as argument):
I'm not giving any pen or demo right here because its easy-as-pie, so lets go straight forward:data.comments
<span class="comment-count"></span>
<script>
$(function () {
var url = 'http://YOUR-URL.com' // Replace this variable value with the link
$.getJSON('http://graph.facebook.com/?id=' + url, function (data) {
if (data.comments) { //If their is no comments on the page then comments data will not exist
$('.comment-count').append(data.comments);
} else {
$('.comment-count').append('No Comments');
}
});
});
</script>
Post A Comment:
0 comments: