要通过AppScript的UrlFetchApp将Google Slides导出为txt文件,可以使用以下代码示例:
function exportSlidesAsTxt() {
// 获取Google Slides的文件ID
var presentationId = 'your-presentation-id';
// 构建导出的URL
var exportUrl = 'https://docs.google.com/feeds/download/presentations/Export?exportFormat=txt&id=' + presentationId;
// 发送请求并获取导出的内容
var response = UrlFetchApp.fetch(exportUrl, {
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
}
});
// 将导出的内容保存为txt文件
var file = DriveApp.createFile(response.getBlob().setName('slides.txt'));
Logger.log('导出成功,文件ID为:' + file.getId());
}
在上述代码示例中,需要将your-presentation-id
替换为实际的Google Slides文件ID。然后,通过使用UrlFetchApp的fetch()
方法发送HTTP请求获取导出的内容。最后,使用DriveApp的createFile()
方法将导出的内容保存为txt文件。
要运行上述代码,可以创建一个Google Apps Script项目,并将代码粘贴到代码编辑器中。然后,保存并运行exportSlidesAsTxt()
函数即可。导出的txt文件将保存在Google Drive中,并且在日志中会打印出文件的ID。
请注意,您需要有足够的权限来访问Google Slides文件和执行Google Apps Script项目。