Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing shared drive with DriveApp

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.

like image 592
mckh123 Avatar asked Sep 30 '19 14:09

mckh123


1 Answers

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)
}
like image 147
ziganotschka Avatar answered Oct 29 '22 22:10

ziganotschka