Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API - List files in a shared folder that I have not accessed yet

I am trying to automate the downloading of files from a Google Drive shared folder. The contents of the folder change daily. The folder is shared to anyone with a link to the folder.

My problem is that the query does not return the new files that I have not opened yet unless I open the new files in Google Drive.

folder_id = 'xxxx...xxx'
results = drive_service.files().list(q=f"parents in '{folder_id}' and trashed = false", fields="nextPageToken, files(id, name)").execute()

Is there a way to list files in a shared folder that I have not opened yet?

I tried to negate the sharedWithMe field but it does not work.

like image 570
donfiguerres Avatar asked Dec 23 '22 17:12

donfiguerres


1 Answers

Yes, there is, but you need to specify that you want to include shared folders into the search

This you can do by setting includeItemsFromAllDrives and supportsAllDrives to true

In python you can implement it with

folder_id = 'xxxx...xxx'
results = drive_service.files().list(supportsAllDrives=True, includeItemsFromAllDrives=True, q="parents in '{folder_id}' and trashed = false", fields = "nextPageToken, files(id, name)").execute()

UPDATE

Mind that shared with anyone with a link means that until you open a file, it is not explicitly shared with you and thus won't show up as part of your file list. If you want to change this, you need to ask the owner to specify you as a viewer of the folder.

like image 169
ziganotschka Avatar answered Apr 19 '23 20:04

ziganotschka