Getting Google File Picker to Work with Drive.File Scope

How do I use Google Picker to access files using the drive.file scope?

As first suggested in a Google+ conversation, the problem can be solved as follows:

  1. Make sure that the Drive SDK is enabled in the Google developer console (the Drive API is something else, and only having that enabled is not enough).
  2. Specify an "Open URL" for your application.

Can I read a drive file opened using Google Picker with drive.file oauth scope?

I found the problem. It works if I move this gapi.load code from pickerCallback:

      return gapi.load('client', function () {
gapi.client.load('drive', 'v2', function () {
gapi.client.setToken({ access_token: authToken });
var file = gapi.client.drive.files.get({ 'fileId': id });
file.execute(function (resp) {
showMessage(resp);
});
});
});

to javascript onload:

  function onGsiLoad()
{
return gapi.load('client', function () {
return gapi.client.load('drive', 'v2', function () {
gsiLoaded = true;
maybeEnablePicker();
});
});
}

And only have gapi.client.drive.files.get in pickerCallback:

      var file = gapi.client.drive.files.get({ 'fileId': fileId });
file.execute(function (resp) {
showMessage(resp);
});

Working test case is here: https://docs.google.com/forms/d/1h3FWKVpGbCApg1_2unD3L86QlOmh9CIwK-W1Q97UTYQ/edit?usp=sharing

Buggy one is here:
https://docs.google.com/forms/d/1jpEa-mp8ccCZhEGlgBN52AML2i1oHIShFpY8Oe3GC44/edit?usp=sharing

Getting Google file picker to work with drive.file scope

Answering my own question thanks to help from folks on the Google Drive Developer discussion on Google Plus:

This does work. I was using the wrong App_ID in my picker implementation - I needed to use only the numeric string at the beginning of the client ID. The other problem, it doesn't work on localhost, only in production.

Full discussion here: https://plus.google.com/u/0/108228914813783364664/posts/RgvmZwJcbE8

Google drive scope (drive or drive.file) to read files uploaded by users

The https://www.googleapis.com/auth/drive.file scope allows you to give a per-file access to files which have been created or opened by your app. Therefore, if the files have been upload manually and not from your app, this scope won't give you the access you require.

As for sharing the files with your application, you might find useful the example listed here in order to prompt a user to share the files wanted.

Reference

  • Drive API v3 Authenticate Your Users;

  • Google Picker API.



Related Topics



Leave a reply



Submit