So far I haven\'t found a good code to create posts in Blogger with Google Script.
In the API Console I got the following credentials:
UrlFetchApp
ScriptApp
function createBlogPost(){
var postUrl = "https://www.googleapis.com/blogger/v3/blogs/blogId/posts";
var blogId = /*"YOUR_BLOG_ID"*/;
postUrl = postUrl.replace("blogId",blogId);
var options = {
method:"post",
contentType:"application/json",
headers: { Authorization: "Bearer "+ ScriptApp.getOAuthToken()},
muteHttpExceptions: true,
payload: JSON.stringify({
title: "Hello from Apps Script!",
content: "This post is automatically created by Apps script"
})
}
var res = UrlFetchApp.fetch(postUrl, options).getContentText();
console.log(res);//or Logger.log(res)
}
Manifest scopes:
"oauthScopes": [
"https://www.googleapis.com/auth/blogger",
"https://www.googleapis.com/auth/script.external_request"
]