Here's a summary about the Blogger feed API that I've collected until now.
There are two ways to request a Blogger blog feed using the feed API in JavaScript. Request can only be made to public blogs with feed enabled and doesn't require authentication:
Inject a script with callback:
<script>
let blogFeed = (function () {
let el = document.createElement('script');
el.src = 'https://xmlexpr.blogspot.com/feeds/posts/default?alt=json-in-script&callback=blogFeed.callback';
el.async = 'async';
document.head.append(el);
function callback(json) {
console.log('blog feed result:', json);
}
return {
callback,
};
})();
</script>Request with fetch:
fetch('https://xmlexpr.blogspot.com/feeds/posts/default?alt=json')
.then(function(response) {
return response.json();
})
.then(function(result) {
// do something with the result
console.log(result);
});Both only works if requested from the same blog page. If you're requesting from an external site or app, use the blogger.com URL. But this only works for the script element and callback method.
<script>
let blogFeed = (function () {
let el = document.createElement('script');
el.src = 'https://blogger.com/feeds/220561901913020919/posts/default?alt=json-in-script&callback=blogFeed.callback';
el.async = 'async';
document.head.append(el);
function callback(json) {
console.log('blog feed result:', json);
}
return {
callback,
};
})();
</script>Replace 220561901913020919 with your target blog ID.
A list of Blogger blog feed parameters that I know:
alt
Feed format. Accepted values are xml, json, json-in-script, and rss. The default format is xml.
callback
Feed callback function. Used together with alt=json-in-script.
prettyprint
Set true to preserve tab and new line characters in the feed response, making it easier to read. Used together with alt=json. Usually for viewing feed response directly in a new tab.
max-results
Maximum feed entries (posts) result. Value must be a number between 1 and 500.
start-index
Retrieve items starting from a specific index. Value must be a number >= 1.
published-min, published-max
Retrieve blog posts published after or before a certain date.
updated-min, updated-max
Retrieve blog posts updated after or before a certain date.
orderby
Apply ordering to the feed items. This parameter must be used together with either published-min/max or updated-min/max parameter. Accepted values are published and updated.
search
Blog search query parameter.
category
Posts label name.
Feed response is limited to 512K in size. So make sure to always use jump break (read more tag) in your posts.
There seems to be a bug that makes it not possible to use orderby and start-index parameters together to retrieve posts over 500 items.
https://www.blogger.com/feeds/3000166519687388789/posts/summary/-/song?alt=json&orderby=updated&start-index=490
Assuming a blog has thousands of posts, in the example URL above:
expected total feed entries is 500, starting from index 490.
actual response: 10.
This issue only happends if you're using fetch API, so you can still get the expected result using inline script with callback parameter.
<script>
let script = document.createElement('script');
script.src = 'https://www.blogger.com/feeds/3000166519687388789/posts/summary/-/song?alt=json&max-results=0&orderby=updated&callback=feedCallback';
document.body.append(script);
function feedCallback(json) {
console.log(json)
}
</script>Feed URL to fetch by post ID:
https://example.blogspot.com/feeds/posts/default?q=post:1359219098896252517To fetch multiple IDs, use the pipe (|) character:
?q=post:1359219098896252517|post:3878451983772065615When this might come in handy?
Blogger API v3 can't retrieve a summary of a post. If you're just scraping the summary of blog posts, this could work as an alternative.
Querying post feed published between two dates.
https://www.blogger.com/feeds/blogId/posts/summary?alt=json&orderby=updated&published-max=2020-11-06T09:22:24.454&published-min=2017-11-06T09:22:24.454&updated-min=2022-08-08T14:53:37.652ZUse the label: query parameter. Quote the label name if it contains whitespaces:
https://www.blogger.com/feeds/7792170602110223490/posts/summary?alt=json&max-results=3&q=label:feeds-chordyFor example, to exclude posts with label uncategorized, use a minus symbol on the label: query parameter:
https://example.blogspot.com/feeds/posts/summary?alt=json&q=-label:uncategorizedFeed API already includes all blog labels on every response, which is kinda wasteful IMO.
Anyway, to retrieve all labels ever posted in a blogger Blog, use any feed URL but add max-results=0 to the feed param to reduce the response size.
https://xmlexpr.blogspot.com/feeds/posts/default?alt=json&max-results=0The labels object can be retrieved from the category key:
"category": [
{
"term": "tips-and-trick"
},
{
"term": "optimization"
},
// ...Some blog posts relating Blogger feed API that you may find useful:
For the feed API, we used to able to retrieve a blog feed using the fetch method from the external site. Today, it's blocked by CORS policy, leaving only the script and callback method available for use.