Using Blogger API with Google Apps Script

Like WordPress, you can also manage your Blogger blogs using Google Apps Scripts. You need to enable the Blogger API from your Google Developers console and also include the Apps Script oAuth2 library in your Google Apps script project. The scope should be set to either of the following depending on whether to want read or write access to blogs.

1. https://www.googleapis.com/auth/blogger
2. https://www.googleapis.com/auth/blogger.readonly

The snippet connects to the Blogger API and fetches the list of Blogger blogs of the currently authenticated users. It then outputs the blog’s ID, name and blog URL in the console log.

In the next example, we using the Blogger API to update the title and content of a blog post through Script. We update the post through Patch Semantics which allows us to send only fields that have changed or need to updated. Since UrlFetchApp doesn’t allow HTTP PATCH requests, we do an HTTP POST request and set the override X-HTTP-Method-Override header to PATCH, as shown below:

Troubleshooting: If you fetching the post status (draft, live or scheduled), you need to set the view parameter as “ADMIN” in the API call. For 403 forbidden errors that say “We’re sorry, but you don’t have permission to access this resource” – it is likely that you have only read-only or view access to a blog.