I would like to use the Google Picker to choose a specific file from Drive, get its id and then share it with some other accounts using Drive API. The problem is that I can either:
- see all of the files user has access to (even as a reader without sharing permissions),
- see only the files where user is the
owner
.
The first option could obviously cause some issues, as sharing won't always work. The second one could hide some files that can in fact still be shared by the user (usually editors
have the rights to share as well).
Is anyone aware of a way to show only shareable files in the Google Picker?
Thanks, Kacper
As far as I can tell, this is not possible with the Google Picker API, but the Drive API may help.
I went over the Google Picker documentation. As you may have seen already, the picker is created with
PickerBuilder()
, which takesView
objects to determine which files will be visible. TheDocsView
subclass has asetOwnedByMe()
method to only show or exclude files that you own, however, this does not check for editor status, and there are no other methods that could do it.View
does have asetQuery()
method, which seemed promising to add a search query, but I tested it and it uses the Drive UI advanced search syntax, which does not have a way to check for editors either. In fact,setQuery()
only prepopulates the search field already included in the picker.As an alternative, since you already plan to use the Drive API you could take the selected file IDs from the picker's
Response.DOCUMENTS
and then plug them in tofiles.get
to first validate whether or not the user has editor access and show a warning before proceeding so they will at least know which files cannot be shared.Also,
files.list
has a search guide that you can check out, and theq
parameter does allow searching for editor status with the query'[email protected]' in writers
. If you really need to only show these files you could write an app that uses only the Drive API instead of Google Picker.PickerBuilder()
generates a live object connected to Drive so there is no easy way to plug in thefiles.list
data to it.