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:
- 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).
- 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
What Is Difference Between "P" and "Pp"
Prefer %W(...) to a Literal Array
Are There Primitive Types in Ruby
Ruby 2.7 Says Uri.Escape Is Obsolete, What Replaces It
Splitting String into Pair of Characters in Ruby
How to Parse a Url and Extract the Required Substring
How to Send an Http Put Request in Ruby
Convert a String of 0-F into a Byte Array in Ruby
How to Stringize/Serialize Ruby Code
How to Memoize a Method That May Return True, False, or Nil in Ruby
Error Installing SQLite3 Gem via Bundler
How to Determine If a String Is Numeric
Ruby Equivalent of PHP's ".=" (Dot Equals) Operator
React Error (Only a Reactowner Can Have Refs.)
How to Use Views and Layouts with Ruby and Erb (Not Rails)
How to Use Private Submit to Hide from Profile
Can't Reindex Sunspot Solr - Error - Rsolr::Error::Http - 500 Internal Server Error