且构网

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

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

更新时间:2023-12-04 21:28:28

使用高级驱动器服务而不是DriveApp

  • 实际上,共享驱动器不受范围有限的DriveApp的支持
  • 但是如果您启用 Advanced Drive Service,则您会能够在Apps脚本中使用 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});
}