Google AppScript: How get last modified user name from file in Google Workspace Team Drive

Viewed 467

I'd like to get name of user who last modify file on Team Drive. I write app in AppScript into Google Sheets.

I checked Revision class, but it returned me only owner name. I use this example: https://www.labnol.org/code/20060-monitor-file-changes-in-drive

In "normal Google Drive" works File class but in Team Drive doesn't work. Also I added aditional service Drive to App, but stell I can't get name or email last file modify user. Has anyone managed to solve this problem?

1 Answers

I believe your goal as follows.

  • You want to retrieve the last modifying user name from a file.
  • The file is put in the shared Drive.

Unfortunately, it seems that the revision list of the file in the shared Drive cannot be retrieved. This has already been mentioned in the question. In this case, I though that the method of "Files: get" in Drive API might be able to be used. The sample script is as follows.

Sample script:

Before you use this script, please enable Drive API at Advanced Google services.

function myFunction() {
  const fileId = "###"; // Please set the file ID.

  const obj = Drive.Files.get(fileId, {supportsTeamDrives: true});
  console.log(obj.lastModifyingUserName)
}

Note:

  • In my environment, the email address cannot be retrieved with obj.lastModifyingUser.emailAddress while the last modifying user name can be retrieved. When your situation is the same with my situation, how about preparing an object including the user name and email address as the key and value, respectively?

Reference:

Related