Reputation: 549
I'm trying to retrieve a specific folder based on a driveId and a folderId. I can easily retrieve a folder by its ID if it's in the user's drive like so:
folder, err := srv.Files.Get(folderId).Do()
If the folderId I pass refers to a folder in a shared drive, then I get a 404 with a message like "googleapi: Error 404: File not found: 1abcdefgh23456789., notFound".
Ideally, I'm looking for something like:
folder, err := srv.Files.Get(folderId).DriveId(driveId).Do()
But that fails because there's no such function ("srv.Files.Get(folderId).DriveId undefined (type *drive.FilesGetCall has no field or method DriveId").
I've tried to workaround this by using the more complex List
method:
res, err := srv.Files.List().Q("id = '" + folderId + "' and mimeType = 'application/vnd.google-apps.folder'").SupportsAllDrives(true).IncludeItemsFromAllDrives(true).Corpora("drive").DriveId(driveId).Do()
But that fails at runtime with "googleapi: Error 400: Invalid Value, invalid". I can use name = '<my folder name>'
but that's obviously not good because there could be duplicate names.
What is the proper way to get a folder in a shared drive by its ID?
Upvotes: 2
Views: 2258
Reputation: 26836
supportsAllDrives
to true
See documentation.
Upvotes: 1
Reputation: 117281
What you are doing is currently correct. The Q parameter for searching is very limited and there is no other way currently to request just the sheared drive.
I suspect what you will need to do is sort though them locally
The file resource has a field called drive id that you could check. Make sure that you add it to fields if its not returning as part of your response.
Upvotes: 1