2

我们需要一份完整的列表,列出在 Google 驱动器上获得特定演示文稿/文档的“共享”查看权限的人员。我们有一个屏幕截图,但可能还不够。我们如何以编程方式检索这些信息?

4

2 回答 2

2

附加到File对象的属性包括三个与用户相关的项目:

  • Owner - 单个User对象,使用File.getOwner().
  • 编辑者-Users对文件具有编辑权限的一组人员,使用File.getEditors(). 包括所有者。
  • 查看器Users-对文件具有只读查看权限的数组,使用File.getViewers(). 包括所有者。

这些只能由文件所有者以编程方式获得。

以下功能是从将已删除的谷歌驱动器文件恢复到目标文件夹的实用程序。该getFileInfo()函数返回一个对象,该对象具有提供的Fileor的属性Folder,包括编辑器和查看器。它会忽略编辑者和查看者列表中的所有者。随意调整它以适应您自己的情况。注意:它依赖于您可以在此 gist 中找到的其他实用程序功能。

/**
 * 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;
}

以下是文件属性的示例:

{ "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"
}

奖励内容

下面是一个脚本,它扫描您 Google Drive 中的所有文件和文件夹,生成包含用户信息的日志。(它没有避免超时的规定,警告购买者!)

/**
 * 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())));
  }
}
于 2013-03-04T03:14:15.133 回答
0

打开共享,复制所有用户,仅将值粘贴到一个新的电子表格中。

于 2021-09-09T10:19:18.530 回答