4

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

  • Having a search parameter can help you out with it. From how I understand it, `sharedWithMe` will retrieve files that are shared to with the authorized user (be it you shared it or another user shared it to you). You can check out other parameters than can be beneficial to you at the [Search for Files](https://developers.google.com/drive/v3/web/search-parameters) page of the Drive API documentation – adjuremods Mar 03 '16 at 08:29
  • `sharedWithMe` only returns files and folders that other users shared with you. What I need is files and folders that I shared with other people. I checked in the page you mentioned but it doesn't say anything regarding that @adjuremods – Ronan Weinberg Waks Mar 03 '16 at 16:35
  • Alright, that's news to me. Yeah, that may then be a limitation with the API. Since you are the only one authenticated, it will then get the files you shared only. – adjuremods Mar 04 '16 at 06:01

1 Answers1

3

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

Frear
  • 31
  • 2