google-apps-script - 将报告文件保存到 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?
解决方案
推荐阅读
- r - 如何按字母文件名导入数据文件,最好使用 tidyverse
- json - 如何使用 Angular 模型解析具有通用名称的 JSON 对象?
- jupyter-notebook - 我不知道是什么问题
- visual-studio-code - 如何在 Visual Studio Code 的突出显示匹配标记扩展中更改匹配标记的下划线?
- python - 用于捕获两个子字符串之间的字符串的正则表达式
- javascript - Vimeo 自动播放和透明度
- mongodb - 何时将集合分解为更小的集合
- django - ModuleNotFoundError:没有名为“rest_framework”的模块。我该如何解决这个错误?
- azure-devops - 如何指向 Azure Pipelines 构建的引用存储库上的特定提交
- regex - 关于 Perl 正则表达式脚本的建议