列出Google云端硬盘上特定演示文稿/文档的所有共享用户 [英] List all shared users of a particular presentation/doc on Google drive

查看:87
本文介绍了列出Google云端硬盘上特定演示文稿/文档的所有共享用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要一份完整的人员列表,这些人员已在Google云端硬盘上获得了特定演示文稿/文档的共享"查看权限.我们有一个屏幕截图,但可能还不够.我们如何以编程方式检索此信息?

We need a comprehensive list of people who have gained "Shared" viewing privileges of a particular presentation/doc on Google drive. We have a screen shot but it may NOT be enough. How may we retrieve this information programmatically?

推荐答案

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

The attributes attached to a File object include three user-related items:

  • 所有者-使用File.getOwner()检索的单个User对象.
  • 编辑者-由Users组成的数组,这些数组对文件具有编辑权限,可使用File.getEditors()进行检索.包括所有者.
  • 查看者-由Users组成的数组,对文件具有只读查看权限,可使用File.getViewers()进行检索.包括所有者.
  • Owner - a single User object, retrieved using File.getOwner().
  • Editors - an array of Users who have editing privileges on the File, retrieved using File.getEditors(). Includes the Owner.
  • Viewers - an array of Users with read-only viewing privileges on the File, retrieved using File.getViewers(). Includes the Owner.

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

These can be obtained programmatically only by the file owner.

以下功能是中的实用程序将垃圾桶中的Google驱动器文件还原到目标文件夹. getFileInfo()函数返回具有提供的FileFolder属性的对象,包括编辑器和查看器.它会忽略编辑器"和查看器"列表中的所有者.随时根据自己的情况对此进行调整.注意:它依赖于其他实用程序功能,您可以在本要点中找到 .

The following function is a utility from Restore trashed google drive files to a target folder. The getFileInfo() function returns an object with attributes of the provided File or Folder, including the Editors and Viewers. It ignores the owner in the Editors and Viewers lists. Feel free to adapt this to your own situation. Note: it relies on additional utility functions you'll find in this 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;
}

以下是文件属性的示例:

Here's an example of a file's 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"
}

奖励内容

下面是一个脚本,该脚本扫描Google云端硬盘中的所有文件和文件夹,并生成包含用户信息的日志. (它没有为避免超时而做的准备,警告购买者!)

Bonus content

Below is a script that scans all files and folders in your Google Drive, generating logs with the user information. (It has no provision for avoiding timeouts, caveat 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())));
  }
}

这篇关于列出Google云端硬盘上特定演示文稿/文档的所有共享用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆