List all users sharing a specific presentation / document on Google Drive.

We need a complete list of people who have received “general” privileges to view a particular presentation / document on Google Drive. We have a screenshot, but this may not be enough. How can we get this information programmatically?

+2
source share
1 answer

Attributes attached to a File object include three user-related elements:

  • Owner is the only User object obtained with File.getOwner() .
  • Editors is an Users array that has edit permissions in a file extracted using File.getEditors() . Includes owner.
  • Viewers - An Users array with read-only viewing privileges in a file, extracted using File.getViewers() . Includes owner.

They can only be obtained programmatically by the owner of the file.

The next function is the utility from Recover files with google files in the target folder . The getFileInfo() function returns an object with attributes provided by File or Folder , including Editors and Viewers. He ignores the owner on the Editors and Viewers lists. Feel free to adapt this to your own situation. Note: it relies on additional utility features you will find in this value .

 /** * Return an object containing relevant information about the given file. * See https://developers.google.com/apps-script/class_file. * From: https://gist.github.com/mogsdad/4644369 * * @param {Object} file File or Folder object to examine. * * @return {Object} Interesting file attributes. * <pre>{ * id: unique id (ID) of the folder or file * name: the name of the File * size: the size of the File * type: The type of the file * created: date that the File was created * description: the description of the File * owner: user id of the owner of the File * otherViewers: list of user ids of viewers of the File, w/o owner * otherEditors: list of user ids of editors of the File, w/o owner * }</pre> */ function getFileInfo (file) { var fileInfo = { id: file.getId(), name: file.getName(), size: file.getSize(), type: (file.getMimeType) ? docTypeToText_(file.getMimeType()) : "folder", // DriveApp Folders don't have getMimeType() method. created: file.getDateCreated(), description: file.getDescription(), owner: userNames([file.getOwner()],false), otherViewers: userNames(file.getViewers(),true), otherEditors: userNames(file.getEditors(),true) }; return fileInfo; } 

Here is an example of file attributes:

 { "id": "0B2kSPNhhUowaRGZKY3VGLUZCREk", "name": "Rescued Files", "size": 0, "type": "folder", "created": "2016-06-13T20:18:14.526Z", "description": "", "owner": " user@example.com ", "otherViewers": "none", "otherEditors": "none" } 

Bonus Content

Below is a script that scans all files and folders on your Google Drive, generating logs with user information. (It has no conditions to avoid timeouts, beware of emptor!)

 /** * Generate logs with user sharing info for all files & folders. */ function showSharing() { var files = DriveApp.getFiles(); var folders = DriveApp.getFolders(); while (files.hasNext() || folders.hasNext()) { var iterator = files.hasNext() ? files : folders; Logger.log(JSON.stringify(getFileInfo(iterator.next()))); } } 
+2
source

All Articles