Using Google Picker with Google Apps Script

The Google Picker API lets you select files and folders in Google Drive visually. It can used inside Google Spreadsheet, Google Docs or a standalone HTML web app.

Here’s a snippet that will let user select one or more Drive folders with the Google File Picker API bound inside a Google Spreadsheet. The dialog window only shows the Folders list and all the other files in the Drive stay hidden. When the user selects a folder, the ID of the Drive folder is printed else the dialog is closed.


// See:

function onOpen() {
  SpreadsheetApp.getUi().createMenu('Google Picker')
      .addItem('Choose Folder', 'showPicker')

 * Displays an HTML-service dialog in Google Sheets that contains client-side
 * JavaScript code for the Google Picker API.
function showPicker() {
  var html = HtmlService.createHtmlOutputFromFile('Picker.html')
  SpreadsheetApp.getUi().showModalDialog(html, 'Select Folder');

function getOAuthToken() {
  return ScriptApp.getOAuthToken();

Also save this file as “Picker.html” inside the Google Apps Script project.



The upcoming release of Save Gmail attachments will include the Google Picker API to help users easily select the Google Drive folder for saving the file attachments.