gpt4 book ai didi

google-apps-script - 列出 Google 云端硬盘上特定演示文稿/文档的所有共享用户

转载 作者:行者123 更新时间:2023-12-05 04:18:26 25 4
gpt4 key购买 nike

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

最佳答案

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

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

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

以下函数是来自 Restore trashed google drive files to a target folder 的实用程序. getFileInfo() 函数返回一个对象,该对象具有提供的 FileFolder 的属性,包括编辑器和查看器。它会忽略编辑者和查看者列表中的所有者。请随意根据您自己的情况进行调整。注意:它依赖于您会发现的其他实用函数 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;
}

这是文件属性的示例:

{ "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())));
}
}

关于google-apps-script - 列出 Google 云端硬盘上特定演示文稿/文档的所有共享用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14397910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com