About

Labels

slider

Recent

Navigation

Complete blogger JSON data to fetch recent comments using Javascript


 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:

<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>

 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.

The feed URL for comment is:
http://www.bloggerever.com/feeds/comments/default?alt=json-in-script&max-results=5&callback=recentcomments
Highlighted 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.
ObjectDescriptionExample
json.feed.entry[i]An array of comments.*No Example
json.feed.entry[i].id.$tA unique id of each comment.tag:blogger.com,1999:blog-6700340609909638752.post-379694332297666401
json.feed.entry[i].published.$tDate and time, the comment published.2014-04-26T01:48:07.825-07:00
json.feed.entry[i].updated.$tDate and time, the comment updated last.2014-04-26T01:48:07.825-07:00
json.feed.entry[i].title.$tReturns a small part of comment in text form.Hi, I would like to subscribe for this web site to...
json.feed.entry[i].content.$tReturns 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].hrefLink 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.$tName of the commentatorHamza
json.feed.entry[i].author.gd$image.srcURL 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.hrefLink 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].valueThis 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
So that is all for JSON path. If found something weird comment below or contact me. :)
Share
Banner

Muhammad Hamza

Themelet provides the best in market today. We work hard to make the clean, modern and SEO friendly blogger templates.

Post A Comment:

0 comments: