Search code examples
javascriptgoogle-apps-scriptgoogle-pickergoogle-drive-picker

Google Picker not showing Shared drive


I am using Google Picker in a Google Sheet Add-in. I am using the following JS to load the API.

  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <script>google.load("picker", "1.0");</script>

And following is code which creates and show the picker, Now I wanted to show the shared drives also to picker window for that I added view.setEnableDrives(true); and .enableFeature(google.picker.Feature.SUPPORT_DRIVES) and it started failing after adding view.setEnableDrives(true);, it works fine (without shared drive) if I remove this line.

function showSheetPicker(config) {
  var view = new google.picker.DocsView(google.picker.ViewId.SPREADSHEETS);
  view.setParent('root');
  view.setIncludeFolders(true);
  view.setEnableDrives(true); // this line gives error

var picker = new google.picker.PickerBuilder()
    .enableFeature(google.picker.Feature.SUPPORT_DRIVES)
    .addView(docsView)
    .addView(folderView)
    .hideTitleBar()
    .setOAuthToken(config.token)
    .setDeveloperKey(config.developerKey)
    .setCallback(onSheetSelected)
    .setOrigin(google.script.host.origin)
    .setSize(700, 500)
    .build();
picker.setVisible(true);

}

Following is the error that I get in the browser console.

userCodeAppPanel:55 Uncaught TypeError: view.setEnableDrives is not a function
    at showSheetPicker (userCodeAppPanel:55)
    at df (1551822985-mae_html_user_bin_i18n_mae_html_user__en_gb.js:72)
    at 1551822985-mae_html_user_bin_i18n_mae_html_user__en_gb.js:15
    at qg.J (1551822985-mae_html_user_bin_i18n_mae_html_user__en_gb.js:99)
    at Kd (1551822985-mae_html_user_bin_i18n_mae_html_user__en_gb.js:47)
    at Gd (1551822985-mae_html_user_bin_i18n_mae_html_user__en_gb.js:48)
    at Ed.b (1551822985-mae_html_user_bin_i18n_mae_html_user__en_gb.js:44)

Any help on this will be much appreciated.


Solution

  • If you debug the view object used in the version 1.0 of the Picker API you will see that there is no setEnableDrives(boolean) method available.

    Try to load a supported version of the API so the documentation will be more consistent. As you can read in the documentation guide you should load the picker API with this method:

    <script>
      function loadPicker() {
          gapi.load('picker', {'callback': showSheetPicker});
      }
    </script>
    <script type="text/javascript" src="https://apis.google.com/js/api.js?onload=loadPicker"></script>
    

    References:

    Picker API docs

    Picker API quickstart guide