I am trying to create a Google Drive Picker that displays the following views:
A "folder" view, displaying the folder tree of the current user, allowing him to only pick files that the current user owns
A "recent" view, displaying the latest opened files, that the current user owns
A "shared drives" view (note: previously named "team drives"), displaying the current user's shared drives that he has access to (he his not owner of the files, as shared drives files are owned by the G Suite platform of the user)
First attempt: Feature.MINE_ONLY
with Feature.SUPPORT_DRIVES
The first thing I tried was to enable both features MINE_ONLY
and SUPPORT_DRIVES
on the PickerBuilder
, however it causes the "shared drives" view to be empty, because the user is not owner of the files in shared drives (see explanation above).
Second attempt: Features.SUPPORT_DRIVE
+ setOwnedByMe(true)
The second thing I tried was to only enable the SUPPORT_DRIVES
feature, and use the setOwnedByMe(true)
method on "folder" and "recent" views.
It almost works as expected, BUT the "folder" view is not displaying folders, because the setOwnedByMe
function cannot be called along with the setIncludeFolders
view (reference).
Following is a simplified version of my code for the second attempt (I intentionally did not put the authentication code):
var googlePicker = new google.picker.PickerBuilder();
// KO: DOES NOT DISPLAY THE FOLDERS
var folderView = new google.picker.DocsView().
//setIncludeFolders(true). // -> cannot be used with setOwnedByMe, else it overrides it
setOwnedByMe(true).
setParent('root');
// OK
var recentFilesView = new google.picker.DocsView(google.picker.ViewId.DOCS).
setOwnedByMe(true);
// OK
var sharedDriveview = new google.picker.DocsView().
setIncludeFolders(true).
setSelectFolderEnabled(false).
setEnableDrives(true);
googlePicker.enableFeature(google.picker.Feature.SUPPORT_DRIVES); // previously named SUPPORT_TEAM_DRIVES
//googlePicker.enableFeature(google.picker.Feature.MINE_ONLY); // NOT working properly with setEnableDrives
googlePicker.
addView(folderView).
addView(recentFilesView).
addView(sharedDriveview);
googlePicker.build().setVisible(true);