I've been discussing Blogger feeds previously about recent posts but this time I collected the JSON path of each data to achieve the recent comments. Secondly it also works cross domain means, you can also get comments of other Blogger blogs to your blog/site, it helps people to manage multiple blogs or show comments on site of the blogs.
Well, its not a complex one to use Javascript to get recent comments. This is an example how to get recent comments:
Well, there is a lot data in Blogger comment feed like Blog name, authors etc. But we actually need comments, so I'll jump on it and giving out the JSON path of those following data only.
<script type='text/javascript'>
function recentcomments(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
var comment=json.feed.entry[i];
for (var j = 0; j < comment.link.length; j++) {
if (comment.link[j].rel == 'alternate') {
var commentlink = comment.link[j].href;
break;
}
}
for (var c = 0; c < comment.gd$extendedProperty.length; c++) {
if (comment.gd$extendedProperty[c].name == 'blogger.displayTime') {
var datePub = comment.gd$extendedProperty[c].value;
break;
}
}
var commentcontent = comment.title.$t,
authorname = comment.author[0].name.$t,
authorimage = comment.author[0].gd$image.src,
item = '<div class="comment-item"><span>' + authorname + '</span> said, "<a href="'+commentlink+'">' + commentcontent + '</a>" on ' + datePub + '</div>';
document.write(item)
}
}
</script>
<script src="http://www.bloggerever.com/feeds/comments/default?alt=json-in-script&max-results=5&callback=recentcomments"></script>
The feed URL for comment is:
http://www.bloggerever.com/feeds/comments/default?alt=json-in-script&max-results=5&callback=recentcommentsHighlighted stuff should edited in a way that www.bloggerever.com will be replaced by any blogger based blog URL, max-results is set to 5 which could be any number of comments return and callback name could be any function name, well in this case its recentcomments.
Object | Description | Example |
---|---|---|
json.feed.entry[i] | An array of comments. | *No Example |
json.feed.entry[i].id.$t | A unique id of each comment. | tag:blogger.com,1999:blog-6700340609909638752.post-379694332297666401 |
json.feed.entry[i].published.$t | Date and time, the comment published. | 2014-04-26T01:48:07.825-07:00 |
json.feed.entry[i].updated.$t | Date and time, the comment updated last. | 2014-04-26T01:48:07.825-07:00 |
json.feed.entry[i].title.$t | Returns a small part of comment in text form. | Hi, I would like to subscribe for this web site to... |
json.feed.entry[i].content.$t | Returns complete comment content in HTML format. Means if someone added any link then the link will be shows too. | Hi, I would like to subscribe for this web site to get most up-to-date updates, so where can i do it please help. |
json.feed.entry[i].link[j].href | Link of the post with hash tag to that comment, that directly shows the comment. | http:\/\/www.bloggerever.com\/2014\/02\/how-to-create-popup-on-button-click.html?showComment=1398502087825#c379694332297666401 |
json.feed.entry[i].author.name.$t | Name of the commentator | Hamza |
json.feed.entry[i].author.gd$image.src | URL of the image of the author, used on Google Plus. In case if author in anonymous then URL will be "http:\/\/img1.blogblog.com\/img\/blank.gif", so you can use if condition to change it with your own image src. | \/\/lh5.googleusercontent.com\/-CPGlkbR67xU\/AAAAAAAAAAI\/AAAAAAAAEeg\/sFtUf8ZJfhI\/s512-c\/photo.jpg |
json.feed.entry[i].thr$in-reply-to.href | Link of the post, without comment hash. | http:\/\/www.bloggerever.com\/2013\/08\/tips-of-using-of-masonry-plugin-on.html |
json.feed.entry[i].gd$extendedProperty[c].value | This one have time and date in standard form but make sure to carryout this value with if condition like one in example above because this is an array. | 18 April 2014 at 22:04 |
Post A Comment:
0 comments: