且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“共享驱动器"Google Apps 脚本中的支持

更新时间:2023-12-04 21:45:22

使用 AdvancedDrive Service 而不是 DriveApp

  • 确实,共享驱动器不受范围有限的 DriveApp 支持
  • 但如果您启用 Advanced Drive Service,你将能够在 Apps Script 中使用 的所有方法支持共享驱动器的 Drive API v2
  • 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
    • 示例:

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