问题
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);
回答1:
Answer:
Unfortunately it looks like this is not possible to do.
Reasoning:
As you pointed out in your question, the issue here boils down to these three things:
- To view Shared Drives,
DocsView.setEnableDrives()
needs to be set totrue
, andFeature.SUPPORT_DRIVES
needs to be on. This can be used in conjunction with bothDocsView.setOwnedByMe()
andDocsView.setInculudeFolders()
on their own. - To view files that are owned by the current user,
DocsView.setOwnedByMe()
needs to be set totrue
, orFeature.MINE_ONLY
needs to be on.Docsview.setOwnedByMe()
can be used withDocsView.setEnableDrives()
, but not withDocsView.setIncludeFolders()
. - To view Folders in the Drive view,
DriveView.setIncludeFolders()
needs to be set totrue
, but can not be set at the same time asDriveView.setOwnedByMe()
as the value ofDriveView.setOwnedByMe()
is ignored whenDriveView.setIncludeFolders()
is set.
Possible workaround:
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.
Feature Request:
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.
References:
- Full Picker Documentation
- DoceView Reference of Drive Picker
- Feature Reference of Drive Picker
- Display the Google Picker Drive API Documentation
- Feature Request on Google's Issue Tracker
来源:https://stackoverflow.com/questions/58231453/google-drive-picker-use-feature-mine-only-along-with-feature-support-drives