首页 > 解决方案 > 将报告文件保存到 G Drive

问题描述

我们运行一个 Google Ads 脚本,每天早上通过电子邮件向我们发送一个 txt 格式的报告文件。我们现在想要在我们的 Google Drive 上使用相同的脚本创建相同的文件。

我们怎样才能做到这一点?

来自 Google Ads 脚本团队的 Matt 建议使用下面的代码段,但我不知道如何使用它,我没有该文件的网址。

function saveFile() {
  var url = "FILE_URL";
  var blob = UrlFetchApp.fetch(url).getBlob();
  DriveApp.createFile(blob);
}

发送电子邮件的功能是:

function SendEmail(recipient, subject, body, message, attachment, mimetype) {
  if (attachment) MailApp.sendEmail(recipient, subject, body, {attachments:[{fileName: attachment, mimeType: mimetype, content: message}]});
  else MailApp.SendEmail(recipient, subject, message);
}

在 function(main) 中有这一行发送电子邮件:

SendEmail("my_email@domain.com", "Stats Report", report[0], report[2], "report.txt", 'text/plain');

任何想法如何使用相同的变量将 report.txt 保存到 Google Drive?

标签: google-apps-scriptgoogle-drive-api

解决方案


推荐阅读