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 .
function getFileInfo (file) { var fileInfo = { id: file.getId(), name: file.getName(), size: file.getSize(), type: (file.getMimeType) ? docTypeToText_(file.getMimeType()) : "folder",
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!)
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()))); } }
source share