問題描述
我正在 Google Apps 腳本中編寫一個 JavaScript 工具來檢查文檔的某些屬性,例如所有鏈接都有效"、權限設置是否正確"等等.我正在使用 https://developers.google.com 中記錄的 API/apps-script/reference/drive/drive-app 按 ID 查找文件、檢查其權限、在 Google Drive 等中定位它們,但我發(fā)現(xiàn)共享驅動器"不能很好地與那個 API.
I am writing a JavaScript tool in Google Apps Script to check some properties of documents, like "are all links valid", "are permissions set correctly", and so on. I am using the API documented in https://developers.google.com/apps-script/reference/drive/drive-app to look up files by ID, check their permissions, locate them in Google Drive etc., but I found that "Shared Drives" don't work very nicely with that API.
例如,
- 對于共享云端硬盤的根文件夾,
Folder.getName()
只返回Drive"而不是 Drive 的名稱, - 即使
mygroup@domain.com
是共享驅動器的管理員",folder.getAccess('mygroup@domain.com')
也是 NONE 并且folder.getViewers()
為空, - 共享云端硬盤中的某些文件夾不(始終)包含在
DriveApp.getFolders()
迭代器.
- for the root folder of a Shared Drive,
Folder.getName()
only returns "Drive" rather than the Drive's name, - even though
mygroup@domain.com
is a "Manager" of the Shared Drive,folder.getAccess('mygroup@domain.com')
is NONE andfolder.getViewers()
is empty, - some folders in Shared Drives are not (always) included in the
DriveApp.getFolders()
iterator.
尤其是第二點現(xiàn)在對我來說是一個障礙,但是我在這里缺少什么?我應該使用其他一些 API,還是我應該報告它只是一個錯誤?是否有一些文檔說明我可以和不可以與共享驅動器一起使用的 Drive
API 的哪些功能?
In particular the second point is a blocker for me now, but what am I missing here? Is there some other API I should be using, or is it simply a bug that I should report? Is there some documentation of what functionality of the Drive
API I can and cannot use with Shared Drives?
推薦答案
使用 AdvancedDrive Service 而不是 DriveApp
- 確實,共享驅動器不受范圍有限的
DriveApp
支持 - 但如果您啟用
Advanced Drive Service
,你將能夠在 Apps Script 中使用 的所有方法支持共享驅動器的 Drive API v2 - Indeed, shared drives are not supported by
DriveApp
which has a limited scope - But if you enable the
Advanced Drive Service
, yuo will be able to use in Apps Script all methods of the Drive API v2 which support shared drives
Use the Advanced Drive Service instead of DriveApp
示例:
function myFunction() {
var sharedDriveName = Drive.Drives.get("XXXXXXXXXXXXXXXXXXX").name;
//it is important to specify that the folder is located on a shared drive with {"supportsAllDrives": true}
var folderOnDriveName = Drive.Files.get("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",{"supportsAllDrives": true}).title;
var folderPermissions = Drive.Permissions.list("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",{"supportsAllDrives": true});
}
這篇關于“共享驅動器"Google Apps 腳本中的支持的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!