Демонстрация возможностей работы с
Вообще, чтобы получить информацию о блоге, зная его ID, можно выполнить
Создать новый пост на основе текста из Документа
Весь UrlFetchApp обернут в fetch
Blogger API
Этот пост обновляется с помощью функцииupdatePost()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updatePost() { | |
// var docExport = Drive.Files.get("1BVEqtuXPmDf3ruLKfeYlkSoDCrDkGLdJpLkHxGwoyqg").exportLinks["text/html"]; | |
// var content = Fetch.get(docExport).getContentText(); | |
var doc = DocumentApp.openById("1BVEqtuXPmDf3ruLKfeYlkSoDCrDkGLdJpLkHxGwoyqg"); | |
var content = doc.getBody().getText(); | |
var title = doc.getName(); | |
var options = { | |
payload: { | |
"kind": "blogger#post", | |
"id": "5780301629671909223", | |
"blog": { | |
"id": "7091170028680816449" | |
}, | |
"title": title, | |
"content": content | |
}, | |
} | |
var response = Fetch.put("https://www.googleapis.com/blogger/v3/blogs/7091170028680816449/posts/5780301629671909223", options); | |
Logger.log(response.getContentText()) | |
} |
getBlog()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBlog() { | |
var response = Fetch.get("https://www.googleapis.com/blogger/v3/blogs/7091170028680816449"); | |
Logger.log(response.getContentText()) | |
} |
createPost()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createPost() { | |
var content = DocumentApp.openById("1BVEqtuXPmDf3ruLKfeYlkSoDCrDkGLdJpLkHxGwoyqg").getBody().getText(); | |
var options = { | |
payload: { | |
"kind": "blogger#post", | |
"blog": { | |
"id": "7091170028680816449" | |
}, | |
"title": "A new post", | |
"content": content | |
}, | |
} | |
var response = Fetch.post("https://www.googleapis.com/blogger/v3/blogs/7091170028680816449/posts", options); | |
Logger.log(response.getContentText()) | |
} |
Комментарии
Отправить комментарий