使用 Google Drive API 转移所有用户文件所有权的最有效流程 [英] Most efficient process for transferring ownership of all of a user's files using the Google Drive API

查看:42
本文介绍了使用 Google Drive API 转移所有用户文件所有权的最有效流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个使用 域范围授权的 Google Apps 脚本函数(Oauth 2 服务帐户)和 Google Drive API 以转移所有 Google 的所有权将用户(用户 A)拥有的文件驱动给另一个用户(用户 B),然后添加第三个用户(用户 C)作为所有文件的编辑者.

I have written a Google Apps Script function that uses Domain-Wide Delegation of Authority (Oauth 2 service account), and the Google Drive API to transfer ownership of all Google Drive files owned by a user (User A) to another user (User B) and then adds a third user (User C) as an editor on all of the files.

我这样做的原因是,我希望在员工离开公司时自动执行保存文件的过程,并为将处理其职责的任何人提供访问权限.

The reason I am doing this is because I want to automate the process of preserving files when an employee leaves the company and providing access to them for whomever will be handling their responsibilities.

  • 用户 A 是离开公司的人,
  • 用户 B 是一个 Google 帐户,专门用于存档已离职人员的文件,
  • 用户 C 是负责接管用户 A 的人责任.
  • User A is the person leaving the company,
  • User B is a Google account meant specifically to be an archive of files from people who have left the company,
  • User C is the person who is responsible for taking over User A’s responsibilities.

Google 为 Apps 管理员提供了转让所有权工具,但它不能通过脚本作为自动化过程的一部分调用,只能通过管理控制台 GUI 调用.

Google provides a Transfer Ownership tool for Apps admins, but it can not be invoked through a script as part of an automated process, only through the Admin Console GUI.

我已经能够使用 API 成功执行此过程的每个步骤,但每个文件需要多次 API 调用.因此,如果用户在其 Drive 中拥有数百或数千个文件,则该功能可能会超过 5 分钟的脚本执行限制.

I’ve been able to successfully perform each step of this process using the API, but it takes several API calls per file. So if the user owns hundreds or thousands of files, in their Drive, the function will likely exceed the 5-minute script execution limit.

有没有办法组合或删除这些步骤中的任何一个,但仍能实现相同的目标?

Is there a way to combine or remove any of these steps and still accomplish the same goal?

这是我想出的过程:

  1. 以用户 A 身份进行身份验证

  1. Authenticate as User A

使用文件:列表,列出所有云端硬盘文件对于归他们所有且不在垃圾箱中的用户 A

Using Files: list, list all Drive files for User A which are owned by them and are not in the trash

遍历每一页结果并将文件详细信息(id、标题、父项等)存储在一个数组中

Loop through each page of results and store the file details (id, title, parents, etc) in an array

使用文件:插入,创建一个根目录-级别容器"文件夹,最终将包含用户 A 的所有文件和文件夹,用于组织目的(称为来自用户 A(日期)"

Using Files: insert, create a root-level "container" folder which will eventually contain all of User A’s files and folders, for organization purposes (called "From User A (date)"

遍历文件详细信息数组中的每个文件.如果文件的父文件是其云端硬盘的根目录,请将父文件设置为容器文件夹(使用 文件:补丁).这会将他们拥有的所有文件移动到容器文件夹中,但会保持子文件夹/文件的目录结构完好无损.

Loop through each file in the file details array. If the parent of a file is the root of their Drive, set the parent to be the container folder (Using Files: patch). This moves all of the files they own into the container folder, but keeps the directory structure of subfolders/files intact.

使用权限:插入,将用户 B 设置为容器文件夹的所有者.这使得容器文件夹出现在用户 B 的驱动器的根目录中.但是,这不会将所有者权限级联到容器文件夹中包含的所有文件/文件夹.

Using Permissions: insert, set User B as an owner of the container folder. This makes the container folder appear in the root of User B’s Drive. However, this does not cascade the Owner permission down to all of the files/folders contained within the container folder.

使用 权限:插入,将用户 C 设置为容器文件夹的编辑器,以便该文件夹显示在其与我共享"文件夹中.

Using Permissions: insert, set User C as an editor of the container folder so that the folder shows up in their "Shared with me" folder.

再次遍历文件详细信息数组中的每个文件,然后:

Loop through each file in the file details array again and:

  1. 使用权限:插入,将用户 B 设置为成为每个文件的所有者

  1. Using Permissions: insert, set User B to be an owner of each file

使用权限:插入,将用户 C 设置为成为编辑器(使用 sendNotificationEmails=false 参数,这样用户 C 就不会被成千上万的通知电子邮件淹没)

Using Permissions: insert, set User C to be an editor (using the sendNotificationEmails=false parameter so User C doesn’t get flooded with thousands of notification emails)

  • 以用户 B 身份验证,再次遍历文件详细信息数组中的每个文件,然后:

  • Authenticate as User B, loop through each file in the file details array again and:

    1. 步骤 8-1 使每个文件也显示在用户 B 的驱动器的根目录中(当您单击每个文件时,它会显示两个父文件夹:容器文件夹和我的驱动器根文件夹),所以现在从每个文件的父数组中删除根文件夹(使用 文件:补丁)

    使用权限:删除,删除用户A的权限来自文件(因为他们的帐户将被设置为前保险柜员工",这会导致他们仍显示在 Google 云端硬盘共享窗格中,但他们不应显示,因为他们已不在公司工作).

    Using Permissions: delete, remove User A’s permission from the file (because their account will be set as a "Vault Former Employee," which causes them to still show up in Google Drive Sharing panes, but they shouldn’t because they are no longer with the company).

  • 推荐答案

    Google 刚刚发布了一个 Data Transfer API 可以完成大部分工作.它不处理与用户 C 相关的部分,但它删除了大部分运行时间最长的步骤.

    Google just released a Data Transfer API that accomplishes most of this. It doesn't handle the parts that relate to User C, but it cuts out most of the steps that took the longest to run.

    这篇关于使用 Google Drive API 转移所有用户文件所有权的最有效流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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