Ronan Weinberg Waks
Ronan Weinberg Waks

Reputation: 51

Google Drive API - Query every shared file (shared with me or I shared with someone else)

Through the Google Drive API is there any way to query every file that is shared? I mean files that either were shared with me or I shared with someone.

I was trying something like this:

not 'me' in owners or ('me' in owners and not 'me' in writers and not 'me' in readers)

Howerver this doesn't work because if a user is the owner of a file, by default that user is a writer and a reader.

I don't want to query every file for the user and then check in my app if the parameter shared=true, that would be a waste of processing time since I am making queries for every user inside an organization (through the domain-wide delegation)

Any help would be really appreciated

Upvotes: 4

Views: 2651

Answers (1)

Frear
Frear

Reputation: 31

I know the question is four years old, but hopefully this answer still helps people.

The query:

( ( not 'provideYourEmailAddressHere' in owners ) or ( visibility = 'anyoneCanFind' or visibility = 'anyoneWithLink' or visibility = 'domainCanFind' or visibility = 'domainWithLink' or visibility = 'limited' ) ) and trashed = false

should do the trick. Or at least be very close :)

The owners portion is intended to find items shared with you. This query term, admittedly, is technically buggy, as people can share things with you then make you the owner. It's meant as an improvement on the sharedWithMe = 'true' query term because that query term seems to return things that we own but are keeping private, which is too broad considering part of the goal is to find things shared with us (that didn't originate from us).

The visibility portion is where we find items shared for others to access. This term has every possible value from the v3 api doc listed because items that are not shared match none of those terms, but items that are shared can match various combinations of those terms.

Finally, the trashed = false portion's purpose should be obvious. If you do want to include such items then of course remove this query term.

This answer is based on the doc at https://developers.google.com/drive/api/v3/ref-search-terms and tested using the files list api explorer at https://developers.google.com/drive/api/v3/reference/files/list

Upvotes: 3

Related Questions