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);
Unfortunately it looks like this is not possible to do.
As you pointed out in your question, the issue here boils down to these three things:
DocsView.setEnableDrives()
needs to be set to true
, and Feature.SUPPORT_DRIVES
needs to be on. This can be used in conjunction with both DocsView.setOwnedByMe()
and DocsView.setInculudeFolders()
on their own.DocsView.setOwnedByMe()
needs to be set to true
, or Feature.MINE_ONLY
needs to be on. Docsview.setOwnedByMe()
can be used with DocsView.setEnableDrives()
, but not with DocsView.setIncludeFolders()
.DriveView.setIncludeFolders()
needs to be set to true
, but can not be set at the same time as DriveView.setOwnedByMe()
as the value of DriveView.setOwnedByMe()
is ignored when DriveView.setIncludeFolders()
is set.As a Picker is only able to render one view at a time, you can create a method of taking information from the user of whether to access a Shared Drive or a Personal Drive before the Picker is created and set the features and includes for the custom render. This could be done in a multitude of ways (such as a button, HTML radio button or bootstrap tab) which changes which Picker is viweable on the page.
I have filed a Feature Request for this on your behalf on Google's Issue Tracker. This Feature Request can be found here, which you can give a star (☆) in the top left to let Google know more people wish for this request.