简体   繁体   English

使用 Google Apps 脚本创建共享云端硬盘(以前称为团队云端硬盘)

[英]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.

相关问题 使用 Apps 脚本在 Google Drive 上使用单元格值作为驱动器名称创建(团队)共享驱动器 - Create (Team) Shared Drives using cell values as Drive Names on Google Drive using Apps Script 使用 Apps 脚本在 Google 共享驱动器(团队驱动器)文件夹之间移动文件 - File movement between Google Shared Drive (team drive) folders using Apps Script 谷歌应用程序脚本,团队驱动的谷歌选择器 - google apps script, google picker for team drive 使用 REST Apps 脚本获取共享驱动器时未找到 Google 共享驱动器 - Google Shared drive not found when getting Shared Drive using REST Apps Script Google Apps 脚本中的“共享驱动器”支持 - “Shared Drive” support in Google Apps Script 如何访问共享(团队)云端硬盘中 Google Apps 脚本的 Stackdriver Logging? - How do I access Stackdriver Logging for a Google Apps Script in a Shared (Team) Drive? 如何使用 Google Apps 脚本 (GAS) 创建多个驱动器文件夹 - How to Create Multiple Drive Folder using Google Apps Script (GAS) Google Apps 脚本将文件移动到团队云端硬盘文件夹 - Google Apps Script moving file to Team Drive folder 使用Apps脚本将图像上传到Google云端硬盘 - Uploading image to Google Drive using Apps Script Google Apps脚本根据文件名将我的驱动器文件移动到Team驱动器文件夹 - Google Apps script move My drive Files to Team drive folder based on file name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM