Accessing shared drive with DriveApp

a 夏天 提交于 2020-06-23 03:47:09

问题


I am trying to create a new file in a shared drive using google apps script so that other people using the shared drive can also access the file. Is there a method on DriveApp that allows me to do that?

I have tried using DriveApp.getFoldersByName but this is for the root folder in my private drive only.


回答1:


You need to use the Advanced Drive Service based on the Drive API

The method Drive.Drives.insert allows you to specify the Drive Id.

Keep in mind that for shared drives, you need to specify the additional parameter supportsAllDrives: true. Also, you need to enable the Advanced Drive Service before using.

Sample:

function myFunction() {  
  var optionalArgs={supportsAllDrives: true};
  var resource = {
    title: 'mySharedFile',
    mimeType: 'application/pdf',
    parents:[{
      "id": "ID OF THE SHARED DRIVE"
    }]
  }  
  Drive.Files.insert(resource, null, optionalArgs)
}


来源:https://stackoverflow.com/questions/58170053/accessing-shared-drive-with-driveapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!