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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With