non-google 用户在调用电子邮件发送后 运行 脚本时,是否有一种未经授权的应用程序脚本中 Doc 到 Docx 的简单方法?

Is there a simply way of Doc to Docx in apps script without authorization for non-google users when they run the script after emailsent being invoked?

只是尝试将 doc 转换为 docx。我的 google 帐户成功保存授权 header 在浏览器上。但是,由于应用程序脚本无法获取此信息,因此我们没有平方。

var options = {
        muteHttpExceptions: false,
        }
      };
      var blb = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/export/Export?id=' + docurl + '&exportFormat=docx',
        options).getBlob();

应该有新的和简单的方法,如果我忽略 httperrors,我可以创建一个 docx,错误说找不到文件。文件在那里但是有这个错误:

Error   
Exception: Request failed for https://docs.google.com returned code 404. 

如果您是 Google 文档的所有者 and/or 您有读取或写入 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。在这种情况下,会发生错误。在这种情况下,请使用 Google 文档 ID。就像 https://docs.google.com/document/d/###/edit 中的 ###

参考: