简单地尝试将doc转换为docx。成功使用我的谷歌帐户是保存授权标题在浏览器上。然而,由于应用程序脚本无法获取这些信息,我们无法确定。
var options = {
muteHttpExceptions: false,
}
};
var blb = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/export/Export?id=' + docurl + '&exportFormat=docx',
options).getBlob();
应该有一种新的简单的方法,如果我屏蔽http错误,我可以创建一个带有错误的docx,比如找不到文件。文件在那里,但存在以下错误:
Error
Exception: Request failed for https://docs.google.com returned code 404.
如果您是Google文档的所有者和/或您有权读取或写入Google文档,则可以使用以下脚本。
修改的脚本:
var docurl = "###"; // Please set the Document ID which is not URL.
var options = {
muteHttpExceptions: true,
headers: { authorization: "Bearer " + ScriptApp.getOAuthToken() }
};
var blb = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/export/Export?id=' + docurl + '&exportFormat=docx', options).getBlob();
DriveApp.createFile(blb); // When you use this script, the converted DOCX is created as a file on the root folder of your Google Drive.
- 在这种情况下,您可以通过
ScriptApp.getOAuthToken()
使用访问令牌。当在脚本中使用DriveApp
时,我认为作用域可以用于使用端点
注意:
- 从
Request failed for https://docs.google.com returned code 404.
的错误消息来看,在您的脚本中,我担心docurl
可能不是Google文档ID。在这种情况下,会发生错误。在这种情况下,请使用谷歌文档ID。这就像https://docs.google.com/document/d/###/edit
的###
参考:
- fetch(url,params(