/google-drive-picker

Promise-based wrapping of Google's Picker API

Primary LanguageJavaScriptMIT LicenseMIT

Google Drive Picker

Promise-based wrapping of Google's Picker API.

Google's JS client library requires a lot of callbacks to load necessary APIs, authorize and build a Google Drive file picker. This project eliminates that boilerplate, wrapping functions in ES6 Promises.

Use

Before using the library you will need to create a project through the Google Developer Console, enable the Google Picker API and create credentials for OAuth and Public API access.

Required: Google's API loaded (https://apis.google.com/js/api.js) and Promise support or a polyfill.

// Build a picker
var picker = new GoogleDrivePicker({
  apiKey:   'myApiKey',
  clientId: 'myClientId'
});

// Use it
picker.pick()
      .then(function(data) {
        // Handle successful response (User selected a file)
        alert(data.docs[0]]);
      });

Detailed configuration can be performed through a function that is yielded a PickerBuilder instance. See the Google Picker API documentation for further information.

var picker = new GoogleDrivePicker({
  apiKey: 'myApiKey',
  clientId: 'myClientId',
  config: function(builder) {
    builder.addView(google.picker.ViewId.VIDEO_SEARCH)
           .enableFeature(google.picker.Feature.NAV_HIDDEN)
           .setLocale('de');
  }
});