Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
563 views
in Technique[技术] by (71.8m points)

javascript - "Shared Drive" support in Google Apps Script

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.

For example,

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...