admin管理员组

文章数量:1336437

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 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.

For example,

  • for the root folder of a Shared Drive, Folder.getName() only returns "Drive" rather than the Drive's name,
  • even though [email protected] is a "Manager" of the Shared Drive, folder.getAccess('[email protected]') is NONE and folder.getViewers() is empty,
  • some folders in Shared Drives are not (always) included in the DriveApp.getFolders() iterator.

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?

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./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.

For example,

  • for the root folder of a Shared Drive, Folder.getName() only returns "Drive" rather than the Drive's name,
  • even though [email protected] is a "Manager" of the Shared Drive, folder.getAccess('[email protected]') is NONE and folder.getViewers() is empty,
  • some folders in Shared Drives are not (always) included in the DriveApp.getFolders() iterator.

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?

Share Improve this question edited Jun 16, 2020 at 14:46 Wicket 38.5k9 gold badges78 silver badges193 bronze badges asked Jun 16, 2020 at 7:45 tgpfeiffertgpfeiffer 1,8582 gold badges21 silver badges23 bronze badges 2
  • 1 Does this answer your question? Accessing Files and Folders in Team Drive – Wicket Commented Jun 16, 2020 at 14:48
  • 2 It is related, but I think the main point I was missing is that (1) yes, I cannot work with Team Drives using the DriveApp API, and (2) I can use the Drive API v2 from within Google Apps Script scripts, which both seem to be already known to the user asking the question in your link. So I think in that regard the question is not exactly a duplicate, and the answer provided by ziganotschka below provided important information to me. – tgpfeiffer Commented Jun 17, 2020 at 1:13
Add a ment  | 

1 Answer 1

Reset to default 6

Use the Advanced Drive Service instead of DriveApp

  • 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

Sample:

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});
}

本文标签: javascriptquotShared Drivequot support in Google Apps ScriptStack Overflow