Tech Bool Tech Bool
Blogger Feed API JavaScript client

Blogger Feed API JavaScript client

February 17, 2025
5 min read
Table of Contents

Fetching feeds from a Blogger site can be a powerful way to manage and display your blog content. Whether you want to display blog posts, pages, or comments directly in your application or website, using a structured library can make this process seamless. The @deox/blogger-feed library is a handy tool for fetching Blogger site feeds effortlessly. In this guide, we’ll explore how to set it up, fetch data, and use the library’s various features.

Introduction to @deox/blogger-feed

The @deox/blogger-feed library provides a straightforward way to access and manage Blogger feeds. You can use it to retrieve posts, pages, comments, and general information about a Blogger blog. It offers flexibility with its options, allowing you to specify things like the number of results to retrieve, making it a great tool for developers looking to integrate Blogger data into their projects.

Installation

You can install @deox/blogger-feed using a package manager like npm, yarn, or pnpm or a CDN.

Using npm (or other package managers)

If you’re using a JavaScript project with a package manager, you can install @deox/blogger-feed with:

npm install @deox/blogger-feed

Or using yarn:

yarn add @deox/blogger-feed

Or using pnpm:

pnpm add @deox/blogger-feed

Using CDN

Include the following script in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/@deox/blogger-feed@0.0.9/dist/blogger-feed.min.js"></script>

Usage

To start fetching feeds, initialize an instance of BloggerFeed by passing in the Blogger site URL. By setting jsonp: true, the library will use JSONP for fetching data, which can be particularly useful if you are working in environments with strict cross-origin policies (only if running in browsers).

Using ES Modules

import { BloggerFeed } from "@deox/blogger-feed";
 
const feed = new BloggerFeed("https://your-blogger-site.blogspot.com", {
  // use jsonp to bypass CORS restrictions
  jsonp: true
});
 
// ...

Using CDN

<script src="https://cdn.jsdelivr.net/npm/@deox/blogger-feed@0.0.9/dist/blogger-feed.min.js"></script>
 
<script>
  const feed = new BloggerFeed("https://your-blogger-site.blogspot.com", {
    // use jsonp to bypass CORS restrictions
    jsonp: true
  });
 
  // ...
</script>

Fetching Blog Information

The first thing you may want to do is retrieve information about the blog itself. This includes data like the title, description, and blog ID. You can retrieve blog information using the blog.get() method.

feed.blog.get().then((blog) => {
  console.log(blog);
});

The result is a Blog object that contains details such as the blog’s name, description, URL, and more.

Fetching Posts

To retrieve posts, you can use the posts.list() method. This method accepts options such as maxResults to specify the number of posts to retrieve.

feed.posts.list({ maxResults: 5 }).then((posts) => {
  console.log(posts);
});

The above example fetches up to 5 posts and stores them in the posts variable. Each item in the array is a Post object containing fields like title, content, author, and publication date.

Fetching Pages

In addition to posts, the library also allows you to fetch pages with the pages.list() method. This function also accepts options similar to posts.list() such as maxResults.

feed.pages.list().then((pages) => {
  console.log(pages);
});

The pages variable contains an array of Post objects, each representing a page from the Blogger site. This feature is especially useful if you want to display static content or specific pages alongside blog posts.

Fetching Comments

The @deox/blogger-feed library also supports fetching comments. To retrieve comments, use the comments.list() method, which accepts options like maxResults.

feed.comments.list({ maxResults: 20 }).then((comments) => {
  console.log(comments);
});

The comments array contains Comment objects with details like the comment’s content, author, and date. This can be useful if you want to display recent comments or analyze comment data.

Example Implementation

Here’s a complete example that combines all the previous steps to fetch the blog information, latest posts, pages, and comments using the CDN version of the library and the jsonp option.

<script src="https://cdn.jsdelivr.net/npm/@deox/blogger-feed@0.0.9/dist/blogger-feed.min.js"></script>
 
<script>
const feed = new BloggerFeed("https://your-blogger-site.blogspot.com", { jsonp: true });
 
(async () => {
  const blog = await feed.blog.get();
  console.log("Blog Info:", blog);
 
  const posts = await feed.posts.list({ maxResults: 5 });
  console.log("Recent Posts:", posts);
 
  const pages = await feed.pages.list();
  console.log("Pages:", pages);
 
  const comments = await feed.comments.list({ maxResults: 20 });
  console.log("Recent Comments:", comments);
})();
</script>

Advantages of Using @deox/blogger-feed

  • Easy Setup: The library requires minimal configuration, making it easy for both beginners and advanced users
  • Comprehensive Data: Fetch various types of data, including posts, pages, comments, and blog details.
  • Flexible Options: Customize requests with options like maxResults and retrieve specific data as needed.
  • Works with CDN: If you’re working on a front-end project, the library can be included via CDN without npm installation.
  • Cross-Domain Requests with JSONP: The jsonp option allows you to fetch data across domains when CORS restrictions are in place.

Conclusion

The @deox/blogger-feed library simplifies the process of fetching and displaying data from a Blogger site. With its flexible methods and the ability to use JSONP for cross-origin requests, it offers an excellent solution for developers looking to integrate Blogger data into their web applications. By using either the npm package or the CDN link, this library offers versatility for various projects.

We hope this guide has helped you understand how to use @deox/blogger-feed effectively. By following these steps, you’ll be able to effortlessly manage and display Blogger data in your applications.