Calvin
Calvin

Reputation: 8765

Can't retrieve file meta data from Google Drive, 404

I'm having some seriously weird issues with the Google Drive API.

Bear with me here, there's a lot to explain.

I originally got the API working using one of my Google accounts -- let's call it [email protected] for simplicity. I got the Google Picker UI working and it correctly displays the list of files in my Drive account.

I set it to my APP_ID and I have some server-side logic that uses the official google-ruby-api-client gem to connect to the Drive API using the drive.files.get endpoint. I can then download the file's metadata using this snippet:

require 'google/api_client'

client = Google::APIClient.new

# client ID and secret from Google APIs Console
client.authorization.client_id = "{CLIENT_ID}"
client.authorization.client_secret = "{SECRET}"
client.authorization.redirect_uri = "http://myapp.com/users/auth/gdrive"
# access token stored in database from oauth2 flow
client.authorization.access_token = "TOKEN"

client.authorization.scope = [
  "https://www.googleapis.com/auth/drive.file",
  "https://www.googleapis.com/auth/userinfo.email",
  "https://www.googleapis.com/auth/userinfo.profile"
]
result = client.execute!(
  :api_method => 'drive.files.get',
  :version => 'v2',
  :parameters => { 'fileId' => params[:file_id] })

With the [email protected] account I tried this on, the result comes back with the file's metadata, and I'm able to download the file. All peachy.

The problem comes when I use a different Google account. I can access the files in Picker, but when the request is sent to the server with the fileId using the above, I just keep getting a 404 error, saying that the file doesn't exist. I've also tried to access the file's metadata using the OAuth 2.0 Playground provided by google, but the weird thing is that I still get that error, but I also get the same 404 error when I use the [email protected] account.

The only thing I can really think of is that I submitted a version of my app with all the Google Drive details once, and installed the app via the Chrome Webstore. After I realized it was showing up for everyone as a Drive-enabled app, I promptly removed it and changed the manifest.json file back to its normal, non-Drive enabled state. I did read that you should have the app installed via the Chrome Webstore to work properly, but I also read that that's not the case anymore. Are your installed Chrome Webstore apps stored in Google's cloud somewhere so they know that it was installed for a particular account? Or are webstore apps just installed locally? I'm so confused.

What am I missing here? I haven't been this frustrated with an API in a really long time. Please help!

Upvotes: 3

Views: 1013

Answers (1)

Calvin
Calvin

Reputation: 8765

Thanks to Ali Afshar for the answer -- the solution (for now) is to temporarily use the full scope of Google Drive instead of just the drive.file scope.

e.g. instead of using this scope,

https://www.googleapis.com/auth/drive.file

use this one instead:

https://www.googleapis.com/auth/drive

Upvotes: 1

Related Questions