[英]Create a Shared Drive (formerly Team Drive) using Google Apps Script
I am trying to ascertain if it possible to create a new Shared Drive (formerly "Team Drive") using Google Apps Script.我试图确定是否可以使用 Google Apps 脚本创建一个新的共享驱动器(以前称为“团队驱动器”)。 I can see plenty examples of creating new folders inside an already-existing team drive, but not creating an entirely new drive.我可以看到很多在现有团队驱动器中创建新文件夹的示例,但没有创建全新的驱动器。
I am hoping to be able to develop an Apps Script to create new team drives containing a pre-prepared structure of folders and documents, that individual teams can tailor to their own specific needs.我希望能够开发一个 Apps 脚本来创建新的团队驱动器,其中包含预先准备好的文件夹和文档结构,各个团队可以根据自己的特定需求进行定制。
This can be done very straightforwardly using the Drive API method, insert这可以使用 Drive API 方法非常简单地完成, 插入
Drive.Teamdrives.insert({name:"My New Team Drive"}, Math.floor(Math.random() * 1000000000000));
The second number simply has to be unique for each request to prevent multiple requests to make the same resource, and can even be entered manually.第二个数字对于每个请求必须是唯一的,以防止多个请求生成相同的资源,甚至可以手动输入。
Regarding the replication of a folder structure: There are multiple ways that can be achieved such as "hard-coding" in each folder creation, or something more complex which refers to a ready-made structure and deep-copies it, but I feel the question is answered in principle with the code snippet above.关于文件夹结构的复制:有多种方法可以实现,例如每个文件夹创建中的“硬编码”,或者更复杂的指的是现成的结构并对其进行深度复制,但我觉得上面的代码片段原则上回答了问题。
you would have to use a service-account.json
(for an account, which has oAuth2 scope https://www.googleapis.com/auth/drive
) in order to create a Team Drive through the Drive API .您必须使用service-account.json
(对于具有 oAuth2 范围https://www.googleapis.com/auth/drive
的帐户)才能通过Drive API创建团队驱动器。 App Script
itself does not feature methods to do that, but one can access just any REST API
with UrlFetchApp . App Script
本身不具备执行此操作的方法,但您可以使用UrlFetchApp访问任何REST API
。 once wrote a client called CloudDatastore.gs , which should provide a good example of how it works, despite it's another API (and I don't intent to write such a drive client, unless being paid).曾经写过一个名为CloudDatastore.gs的客户端,它应该提供一个很好的例子来说明它是如何工作的,尽管它是另一个 API(我不打算编写这样的驱动客户端,除非付费)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.