get facebook comment count with jquery
How would I use jQuery to get the comment count of a specific url, The url has comments added with facebook comments b开发者_JAVA百科ox
Also is there an option to get a combined comment count of all urls that start with the same domain?
You can use simple a JSON request and pluck the comment count off of it
function getCommentNum() {
$.getJSON("https://graph.facebook.com/[your facebook user id]_[story id of post]?callback=?", function(json) {
alert(json.comments.count);
});
}
<div class="aaa"></div>
function getFacebookCommentCount(url, callback) {
$.getJSON('https://graph.facebook.com/?ids='+url, function(data) {
if(url && url != '#' && url != '') {
if(!data['error']) {
callback(data[url]);
}
}
});
}
getFacebookCommentCount('http://example.com/', function(callback) {
$('.aaa').html(callback['comments']+'-'+callback['shares']);
});
test on: http://jsfiddle.net/rg2BU/ used on: http://www.xaluan.com
精彩评论