2

Basically I have a program to do few things on a shared drive. There are around 15 people uploading audio files once a day simultaneously. The account associated with the program is the owner of the shared drive where they upload the files.

The problem occurs when I tell the program to execute the function drive.files().delete(fileId=id).execute() to remove these audio files after downloading them but it raises Permissions Error.\

I tried to upload my own files and then try to remove them with the function and it does so very well.

So my conclusion is that I have to be owner of the files to deleting them, but in the Google Drive API wiki it says that a owner account of the shared drive where the files are can delete them too, so I'm very confused. "Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive the user must be an organizer on the parent.." Link: https://developers.google.com/drive/api/v3/reference/files/delete?hl=en

I don't know what to try now

Josh Zhang
  • 127
  • 1
  • 8

1 Answers1

1

As mentioned in the official document that you provided, If the file belongs to a shared drive the user must be an organizer on the parent... You need to have a Manager permission to delete the files not owned by you using Files.delete()

enter image description here


Note:

Don't forget to set supportsAllDrives to true when deleting files on your shared drive. drive.files().delete(fileId=id, supportsAllDrives=true).execute()

Ron M
  • 5,791
  • 1
  • 4
  • 16
  • Tried this using the api explorer and I was able to delete files not owned by me in the shared drive that was owned by me – Ron M Aug 03 '21 at 17:16
  • That was very useful, thanks you. But i can't change the ownership of the file, maybe there is a funcion to do that? Or how to give me the "Manager" permission without being the owner? – Mathias González Aug 06 '21 at 16:42
  • Go to your shared drive folder and select `view members` or `manage members` and see if the account that you used in calling the drive api has `manager` permission – Ron M Aug 06 '21 at 16:50
  • You could also follow this reference materials: [Specific roles for shared drives](https://developers.google.com/drive/api/v3/about-shareddrives#specific_roles_for_shared_drives) and [Create a permission](https://developers.google.com/drive/api/v3/manage-sharing#create_a_permission) – Ron M Aug 06 '21 at 16:56
  • This account owns the folder where the audio files are, but it is only the editor of the audio files, so I can't delete them. Now i have a question, what do you mean by shared drive? Because the main folder is into "My Drive" in the account that I am using and inside that folder are all the other folders and audios which I have shared to other users. So is this a shared drive or not? I never see "roles" like "organizer" and "file organizer". I just see Owner, Editor, Viewer and Commenter. – Mathias González Aug 06 '21 at 18:52
  • I thought you are using a shared drive as mentioned in your post `Basically I have a program to do few things on a shared drive`. But it seems what you actually did is sharing your drive folder. – Ron M Aug 06 '21 at 18:55
  • I suggest that you use a `shared drive` instead of sharing a folder in your MyDrive for you to be able to delete files via drive api easily. [Setup Shared Drive](https://support.google.com/a/users/answer/9310249?hl=en). Or else you need to be an owner of the file that you want to delete in your shared folder as mentioned by @DalmTo – Ron M Aug 06 '21 at 19:02