使用应用脚本将 google 幻灯片转换为图像时出错
Error converting google slide to image using app script
这是我用来将 google 幻灯片转换为图像的代码:
function myFunction() {
var dApp = DriveApp;
var folder = dApp.getFoldersByName("til");
var til = folder.next();
var filesIter = til.getFiles();
var i = 0;
while(filesIter.hasNext() && i < 50){
var file = filesIter.next();
Logger.log(file.getId());
exportSlideImages(file.getId(), file.getName())
break;
i = i + 1;
}
}
function exportSlideImages(presentationId, imageName) {
var presentation = SlidesApp.openById(presentationId);
var baseUrl =
"https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}/thumbnail";
var parameters = {
method: "GET",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
muteHttpExceptions: true
};
presentation.getSlides().forEach(function(slide, i) {
var url = baseUrl
.replace("{presentationId}", presentationId)
.replace("{pageObjectId}", slide.getObjectId());
var response = JSON.parse(UrlFetchApp.fetch(url, parameters));
Logger.log(response)
var blob = UrlFetchApp.fetch(response.contentUrl).getBlob();
blob.setName(imageName +'.png');
DriveApp.createFile(blob);
});
}
它确实创建了一个图像文件,但我在文件中得到了这个输出:
"code": 403,
"message": "Google Slides API has not been used in project 396798675804 before or it is disabled. Enable it by visiting
(a link was given here to)
then retry. If you enabled this API recently, wait a few minutes for
the action to propagate to our systems and retry.",
但我不明白的是我没有任何 ID 为 396798675804 的项目。我做错了什么??有什么指点吗??
您必须启用 Google Slides Advanced 服务,因为您的代码正在使用 UrlFetchApp 调用 Slides API
相关
这是我用来将 google 幻灯片转换为图像的代码:
function myFunction() {
var dApp = DriveApp;
var folder = dApp.getFoldersByName("til");
var til = folder.next();
var filesIter = til.getFiles();
var i = 0;
while(filesIter.hasNext() && i < 50){
var file = filesIter.next();
Logger.log(file.getId());
exportSlideImages(file.getId(), file.getName())
break;
i = i + 1;
}
}
function exportSlideImages(presentationId, imageName) {
var presentation = SlidesApp.openById(presentationId);
var baseUrl =
"https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}/thumbnail";
var parameters = {
method: "GET",
headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
contentType: "application/json",
muteHttpExceptions: true
};
presentation.getSlides().forEach(function(slide, i) {
var url = baseUrl
.replace("{presentationId}", presentationId)
.replace("{pageObjectId}", slide.getObjectId());
var response = JSON.parse(UrlFetchApp.fetch(url, parameters));
Logger.log(response)
var blob = UrlFetchApp.fetch(response.contentUrl).getBlob();
blob.setName(imageName +'.png');
DriveApp.createFile(blob);
});
}
它确实创建了一个图像文件,但我在文件中得到了这个输出:
"code": 403, "message": "Google Slides API has not been used in project 396798675804 before or it is disabled. Enable it by visiting (a link was given here to) then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
但我不明白的是我没有任何 ID 为 396798675804 的项目。我做错了什么??有什么指点吗??
您必须启用 Google Slides Advanced 服务,因为您的代码正在使用 UrlFetchApp 调用 Slides API
相关