Google Drive API: search for all the files that I can edit, including those in shared drives

1k views Asked by At

I think the title is pretty explicit. I've read and read (and read) the search files doc, without success.

The problem is when I try to list the files that I can edit because I'm a contributor or manager of the shared drive they're located in: I have no direct permission on the files, I can edit them thanks to the inheritance.

I've tried to run the files.list request with q = 'myadress' in writers or 'myadress' in owners and it returns all the files I can edit except the case described above.

(Yes I set all the options relative to shared drive to true).

Are included in this search:

  • the files in a "regular" drive that I can edit
  • the files in a shared drive when I have an explicit "writer" permission on the file

Are excluded:

  • the files that I can edit because they're in a shared drive I'm manager of (or contributor)

Is there any way to get all those files in one shot?

edit: to make it clear, I'm only interested in the files that I can edit. I could list all the files visible to me, and then check in the response object if I can edit them or not, but that would mean listing way more files than necessary.

Thanks !

1

There are 1 answers

4
iansedano On

You are right, that's not possible

I believe I have similar results to you:

The q parameter

Search query terms

To search for files, use the q parameter in files: files.list.

In the article cited above, there are many parameters for files in your main drive, for example: writers, owners, readers.

Yet if I made any request with a query containing in writers or in owners, if I could edit a file only because I was a member of the parent shared drive then it would not show up. It would only show up if someone had gone into the individual document and given me edit permission.

I could use other q parameters such as fullText and that would return shared drive items no problem.

UPDATE: It seems Google are aware of this issue now, https://issuetracker.google.com/171363628. Go and put a ☆ on it to let them know it affects you.


Possible workarounds

You probably know these well, but I'll list them anyway for the benefit of future users.

Limit the fields

Reference

For example, using a request with the following parameters:

corpora = allDrives
includeItemsFromAllDrives = true
pageSize = 1000
supportsAllDrives = true
fields = files/id, files/name, files/capabilities/canEdit
key = [YOUR_API_KEY]

Which involves greatly limiting the fields returned for better performance and efficiency. In this case, only the id, name and a boolean for whether the user can edit are returned. In this request the pageSize is set to the maximum allowed.

Once you have this response, you could filter it in memory. As you suggested.

Make a few requests

I am not sure if you are running into quota issues, in which case, this option may not be practical for you.

If you are not averse to making a few calls to the API, is to identify the shared drives you have edit access to. By necessity you will have edit access on the files contained therein. Once you have identified the whether you can edit a certain shared drive. You can make a request of each shared drive and your main drive. Which depending on how many shared drives you have and how often they change, could be practical enough for you.

If the shared drives don't change very often at all, you could just keep a list of the shared drive IDs, which you could update periodically with an automatic script. So you are making one less request.