TL;DR: Is there a way to access the change log from a Google Drive File in Google Scripts, or is there a way to scrape this information with a JavaScript function? I simply want the most recent editor's name, and at what time they performed the edit. You can view this on Google Drive, but I cannot find a method that accesses it.
Hey guys, so I work for a small company which stores all its data in shared Google Drive folders. Certain folders contain valuable files, in which Management would like to keep track of changes too.
I am trying to implement a Google Script which would send an email out at the end of a week, notifying management of all changes made to a document.
I currently have code that will iterate through a folder, with a conditional statement that runs if a file has been edited within 7 days. I know how to trigger the code to run, and how to create an email once I gather the necessary info.
function myFunction() {
var files = DriveApp.getFiles();
while (files.hasNext()) {
var file = files.next();
if (new Date() - file.getLastUpdated() < 7 * 24 * 60 * 60 * 1000){
//This is where I would log the necessary info
}
}
}
You can indeed access revision history by using the Drive API (please look at the documentation next time before asking the question, especially considering that Google provides you with quite detailed and easy to navigate documentation).
You can get all the revisions by using revisions = Drive.Revisions.list('fileID')
. Then revisions.items[i].lastModifyingUserName
or revisions.items[i].lastModifyingUser.displayName
will give you the username and revisions.items[i].modifiedDate
will get you the date. It seems like from [0]
to [n]
the modified date increases so you may want to go from revisions.items.lenght
down to 0
and stop once you go above 1 week old (though I cannot guarantee that as all I did was take a quick look)