谷歌驱动器/电子表格 - 在子文件夹中修改文件时的电子邮件通知
我已经设置了一个谷歌驱动器文件夹结构,可以使用2级子文件夹工作。例如谷歌驱动器/电子表格 - 在子文件夹中修改文件时的电子邮件通知
主文件夹
- 面积1
---豁免区
- 面积2
---豁免区
我需要一个电子邮件通知的时间文件被修改以确保其他用户必须获得最新的数据。我在网上找到了一个主要工作的脚本,但我需要它能够在子文件夹中检查这个脚本没有做的修改。任何帮助,将不胜感激。谢谢,阿曼达
function GoogleDriveModifiedFiles(){
// Folder ID "XXXXXXXxxXXXwwerr0RSQ2ZlZms" of the folder to monitor for changes
var folderID = '"' + "0Bwz931NfDj3HUnhTVXBuc1lqMTg" + '"';
// Email Configuration
var emailFromName ="Work Google Drive (Do Not Reply)";
var emailSubject = "Work Google Drive content has been modified";
var emailBody = "<br>You are receiving this email because a folder/file shared with you on Google Drive has been modified, click on the link to view new content<br>"
var emailFooter = "Any questions please contact [email protected]";
var folderSearch = folderID + " " + "in parents";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var email = sheet.getRange("E1").getValue();
var timezone = ss.getSpreadsheetTimeZone();
var today = new Date();
var oneDayAgo = new Date(today.getTime() - 1 * 60 * 1000);
var startTime = oneDayAgo.toISOString();
var search = '(trashed = true or trashed = false) and '+ folderSearch +' and (modifiedDate > "' + startTime + '")';
var files = DriveApp.searchFiles(search);
var row = "", count=0;
while(files.hasNext()) {
var file = files.next();
var fileName = file.getName();
var fileURL = file.getUrl();
var lastUpdated = Utilities.formatDate(file.getLastUpdated(), timezone, "dd-MM-yyyy HH:mm");
var dateCreated = Utilities.formatDate(file.getDateCreated(), timezone, "dd-MM-yyyy HH:mm")
row += "<li>" + lastUpdated + " <a href='" + fileURL + "'>" + fileName + "</a></li>";
sheet.appendRow([dateCreated, lastUpdated, fileName, fileURL]);
count++;
}
if (row !== "") {
row = "<p>" + count + " file(s) changed:</p><ol>" + row + "</ol>";
row += emailBody+"<br>" + "<br><small> "+emailFooter+" </a>.</small>";
MailApp.sendEmail(email, emailSubject, "", {name: emailFromName, htmlBody: row});
}
}
我不知道,如果驱动器API有电子邮件通知。但是,此document描述了如何使用push notifications
在资源更改时通知您的应用程序。您可以使用此功能来改善应用程序的性能。它允许您消除额外的网络并计算轮询资源所涉及的成本,以确定它们是否发生了变化。每当观看的资源发生变化时,Drive API都会通知您的应用程序。
要使用推送通知,你需要做三件事情:
- 注册您的接收网址的域名。
例如,如果你打算使用https://exampledomain.com/notifications作为接收URL,你需要注册https://exampledomain.com。 *设置您的接收URL或“Webhook”回叫接收器。
这是一个HTTPS服务器,用于处理资源更改时触发的API通知消息。
- 为要观看的每个资源端点设置通知通道。
通道指定通知消息的路由信息。作为频道设置的一部分,您需要确定要接收通知的特定网址。只要通道的资源发生变化,Drive API就会将通知消息作为POST请求发送到该URL。
对于那些需要跟踪变化的文件,请点击此链接谷歌云端硬盘应用:https://developers.google.com/drive/v3/web/manage-changes
我做了一些研究回合这个问题,并发现此Feature request。目前它不支持文件夹级别更改的通知。