I'm trying to display Facebook comment counts in <div id="comments">
It has to be via Facebook Query Language (FQL). This post is almost exactly what I need: Facebook Graph Api url comments and shares count doesn't work anymore
But how do I display the comment_count
(from the query) into a div
? i.e. how do I process that data? So far, I have:
$(function(){
$.ajax({
url: 'https://graph.facebook.com/fql?q=SELECT%20comment_count%20FROM%20link_stat%20WHERE%20url=%27e',
dataType: 'jsonp',
success: function(data) {
if(data.comment_count)
{
$('body').find('#comments').html('Comments ('+jsonp.data.comment_count+')');
}else{
$('body').find('#comments').html('Comments (0)');
}
}
});
});
I did it like this to update my div with the likes count like this
works for me like a charm.
For my part,
I used php code to get the comment count via fql. First, you need to download the facebook php sdk and load it at the top of your page:
Then, the fql query:
So, $cmcount is now your comment counts, put it directly in your html code: