2
votes

I have a Google Drive that contains hundreds of files that are currently referenced and then linked within a PHP webapp. Users authenticate with the webapp and not with Google. I want use the Google Picker and point it at this shared, but private, Google Drive so users can access these documents.

I've seen a load of examples where the Picker is used to access the users Google Drive but not where Picker is pointing to another Google Drive.

I'm migrating from Google Documents List API v2 where this functionality is available, but the PIcker is far better solution.

Is there a way to accomplish this?

2

2 Answers

3
votes

If your using the Google Picker from here https://developers.google.com/picker/docs then you can set one view for not shared drives and another one for shared drives, this will appear as two tabs on the picker

enter image description here

     const docsView = new google.picker.DocsView(googleViewId)
       .setIncludeFolders(true)       
       .setSelectFolderEnabled(true);

      const folderView = new google.picker.DocsView(googleViewId)
        .setIncludeFolders(true)
        .setEnableDrives(true)
        .setSelectFolderEnabled(true);

  const picker = new window.google.picker.PickerBuilder()
    .enableFeature(google.picker.Feature.SIMPLE_UPLOAD_ENABLED)
    .enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
    .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
      .addView(docsView)
      .addView(folderView)
      .setOAuthToken(oauthToken)
      .setDeveloperKey(Config.googlePickerApiKey)
      .setCallback((data)=>{
        if (data.action === google.picker.Action.PICKED) {
            // var fileId = data.docs[0].id;                
            onSelect(data.docs)
        }
      });
0
votes

It's not documented but you can set a Google user ID while building a new picker.

var picker = new google.picker.PickerBuilder().setAuthUser(<userId>)...