Get Blogger feeds using javascript
Google Blogger is the famous blogging service used by a lot of people in the world. Is a good service but is quite basic and is not possible to customize so much by default. However some new features can be "added" by using some javascript code. In this tutorial will explain how to "extract" blog feeds through javascript showing an example of possible use.
Blogger feeds are basically a json structure containing a lot of information regarding each single blog post. Please, note a very important point, for allow the javascript code to work correctly the blog need to have the following conditions:
- The blog must to be set as public (since private blog doesn't export feeds data)
- The feeds must be enabled in blog settings panel
Once verified these conditions we can proceed with explanations. Basically the way to get blogger feed is to format url address in this mode:
http://myblogname.blogspot.com/feeds/posts/default?alt=rss
This will return an XML file in RSS format containing feeds data. Changing the url params a follow will show the same data but in json string format:
http://myblogname.blogspot.com/feeds/posts/default?alt=json
As you can see making some test the string returned is very long. This because the data returned contains a lot of information about each post published in the blog. If you want to know the json structure you can use the various web site able to convert the string to the tree structure like, for example, this one. Our final goal, however, is to get and elaborate these data using javascript language. For this reason we need to change the the blog url as follow:
http://myblogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=MyJavascriptFunc
This particular format will instruct Blogger platform to call the javascript function MyJavascriptFunc passing as single param the feeds structure to elaborate. In our example, however, will introduce two additional params as follow:
http://myblogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=MyJavascriptFunc&max-results=1000&start-index=1
The params max-results and start-index, as you can know, instruct Blogger platform to return a maximum number of feeds of 1000 (in this url example) starting from the first feed available ordered by the last published. In the various examples on the same topic you can find around quite all set the max result value to some number like 999999999 for have all the feeds returned in one call. However, googling around, it seem there is the suspect Google set a max limit of feeds is possible to get in a single call. As usual this "official" limit is undocumented than, just for avoid problems, in this example I'll choose to extract the feeds with steps of 1000, you can increase this value if you want. Follow the full source of the javascript code:
<script type="text/javascript"> var StartIndex = 1; var MaxResults = 1000; function MyJavascriptFunc(BlogData) { var Feed, i; for(Feed = BlogData.feed, i = 0; i < Feed.entry.length; i++) { var PostUrl, ImgUrl, Entry, Content, Title, x; Entry = Feed.entry[i]; Content = Feed.entry[i].content.$t; Title = Feed.entry[i].title.$t; ImgUrl = PostUrl = ''; if(typeof Feed.entry[i].media$thumbnail !== 'undefined') { ImgUrl = Feed.entry[i].media$thumbnail.url; } for(x = 0; x < Entry.link.length; x++) { if(Entry.link[x].rel == 'alternate') { PostUrl = Entry.link[x].href; break; } } // Here you have all basic post data, use as you like // .... } if(i < MaxResults) { // All the feeds has been extracted } else { var ScriptObj = document.createElement('script'); var FeedsUrl = 'http://myblogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=MyJavascriptFunc&max-results=' + MaxResults + '&start-index='; StartIndex = (StartIndex + MaxResults); ScriptObj.src = (FeedsUrl + StartIndex); document.body.appendChild(ScriptObj); } } function StartFeedsExtraction() { var ScriptObj = document.createElement('script'); var FeedsUrl = 'http://myblogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=MyJavascriptFunc&max-results=' + MaxResults + '&start-index='; ScriptObj.src = (FeedsUrl + StartIndex); document.body.appendChild(ScriptObj); } </script> <script type="text/javascript"> StartFeedsExtraction(); </script>
Now let's go to explain each single piece. At first we need the single javascript line calling the main extracting function StartFeedsExtraction(). You can put this code everywhere into the page with the only condition it have to be placed after the main function body:
<script type="text/javascript"> StartFeedsExtraction(); </script>
This call start the feeds extraction process. Basically it dynamically insert a call to a formatted url for get the blog feeds. Once process started correctly the MyJavascriptFunc() was automatically called with the requested feeds data range. The first for cycle extract the basic post info like content, title, post url and image url (if image present, usually is the first image of the post). If you need more data you have to examine the post tree structure as described above and read the additional info you want. The second condition if(i < MaxResults) check if all feeds has been extracted. Since we asked a maximum number of feeds of MaxResults (that is 1000 in our example) if the feeds number returned is not minor to this value it probably mean there are additional feeds available. In this case repeat the operation to dynamically ask for new feeds by increase the starting index for the next range. In case is minor it mean all the feeds has been extracted and the operation can be concluded. Please note same operation can be done by extracting feeds connected to some label only. This will require to change the url as follow:
http://myblogname.blogspot.com/feeds/posts/default/-/MyLabel/?alt=json-in-script&callback=MyJavascriptFunc
This will return the feeds of the post containing the MyLabel tag. This can be useful in case you want to separate the various sources. Since the amount of data returned is quite big you can reduce then by configuring Blogger platform to return feeds only for post data and ignore comments for example. Check the options available in blog settings panel.
Looking to add extra style to your content, make use of our strikethrough Text Generator to add amazing line through text in desired platform. Strikethrough in Google Docs.
ReplyDeleteGreat blog and informative post..
ReplyDeleteSAP Training in Chennai
SAP ABAP Training in Chennai
SAP Basis Training in Chennai
SAP FICO Training in Chennai
SAP MM Training in Chennai
SAP PM Training in Chennai
SAP PP Training in Chennai
SAP SD Training in Chennai
Amazing blog...
ReplyDeleteORACLE TRAINING IN CHENNAI
ReplyDeleteINSTALL RPMS DIRECTORY
INTERVIEW QUESTIONS APTITUDE
INTERVIEW QUESTIONS VERBAL REASONING
FLIPKART WALLET HACK TOOL
INTERVIEW QUESTIONS CHEMISTRY
TUTORIALS C PROGRAMMING
BEST APACHE PIG TUTORIALS
TOP APTITUDE INTERVIEW QUESTIONS
APACHE PIG TOKENIZE FUNCTION
RESUME FORMAT FOR RETIRED GOVERNMENT OFFICER
Amazing information
ReplyDeleteSAP ABAP Training in Chennai
SAP FICO Training in Chennai
SAP MM Training in Chennai
SAP SD Training in Chennai
SAP Training in Chennai
OBIA online training Evanta technologies provide you the best OBIA online training with step by step procedure for installing, customizing and configuring of OBIA.
ReplyDeleteInformative and nice blog post. Thanks for this wonderful Post.
ReplyDeleteSAP Training in Chennai
AWS Training in Chennai
Hardware and Networking Training in Chennai
QTP Training in Chennai
CCNA Training in Chennai
Great Blog. Thnaks.
ReplyDeleteSAP Training in Chennai
Java Training in Chennai
Software Testing Training in Chennai
.Net Training in Chennai
Hardware and Networking Training in Chennai
AWS Training in Chennai
Azure Training in Chennai
Selenium Training in Chennai
QTP Training in Chennai
Android Training in Chennai
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteOracle Training | Online Course | Certification in chennai | Oracle Training | Online Course | Certification in bangalore | Oracle Training | Online Course | Certification in hyderabad | Oracle Training | Online Course | Certification in pune | Oracle Training | Online Course | Certification in coimbatore
Excellent Post.
ReplyDeleteCCNA Training
Java Training
AWS Training
PHP Training
Android Training
Oracle Training
Selenium Training
Hardware and Networking Training
SAP Training
Software Testing Training
Thanks for this post.
ReplyDeleteJava Training in Chennai | Java Training Institute in Chennai | Java Training Center in Chennai | Best Java Training in Chennai | Java Training
Very good post, thank you. I am surprised to find your website
ReplyDeleteSEO Training in Pune
SEO Training in Mumbai
SEO Training in Delhi
SEO Training in Bangalore
SEO Training in Hyderabad
I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Youtube Mp3 Converter
ReplyDeleteThis comment has been removed by the author.
ReplyDeletenice article .
ReplyDeletejson formatter
Thanks for sharing the valuable information…
ReplyDeleteDo you want to learn SAP Training Course? Don’t worry we provide the best SPA Training for all SAP modules in Laurel, MD.
Thanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.
ReplyDeleteVisit us: Dot Net Online Course
Visit us: .Net Online Training
This post is so helpfull and informative.Keep updating more information
ReplyDeleteGraphic Designing in Mumbai
Graphic Design courses in Ahmedabad
Graphic Designers in Kochi
Graphic Design institute in Trivandrum
Graphic Designing in Kolkata
I really enjoy the blog article.Much thanks again.
ReplyDeletejava online classes
core java online course
To know about automated help desk and service desk with rezolve.ai, click here: https://bit.ly/3ttcaGK
ReplyDeleteTo know about automated AI helpdesk and servicedesk with rezolve.ai, visit their website. To know more click here: microsoft teams modern help desk
ReplyDeleteThis post is so useful and informative. Keep updating with more information.....
ReplyDeleteSpoken English Classes in Bangalore
English Speaking Course in Bangalore
brigunXas-e Matt Palma Download
ReplyDeletetralentome
This is good blog i like it very much.
ReplyDeleteReiboot Crack
Powtoon Crack
Pubg Crack
UVK Ultra Virus Killer Crack
Nice Post. You are Share great post and keep posting.
ReplyDeleteSitecore Training
AEM Training
Dellboomi Training
IBM Maximo Training
Guidewire Training
Kronos Training
OclivcomKhie_wo1978 Gina Glover Waves Complete 14 (17.08.22)
ReplyDeleteAdobe Illustrator
software
ArtMoney 8.12.1 + Pro VIP
myiberwari
This comment has been removed by the author.
ReplyDeleteVery Informative
ReplyDeleteGraphic Design Course Training Institute in Mumbai
That's really great blog.
ReplyDeleteFull stack course in Pune
Nice blog article, thanks for sharing
ReplyDeletedevops training in hyderabad
Thanks for the post.I Really enjoyed your blog.
ReplyDeleteJava Course in Nagpur
Master Java Enterprise Edition (J2EE) with our specialized Java J2EE Training in Chennai. Visit - maasmind.com
ReplyDeleteVery interesting. Thanks for posting.
ReplyDeleteJava Classes in Pune