Reputation: 119
I have an image file that I obtained using GoogleFilePicker. Using the FileId from GoogleFilePicker, I'm trying to retrieve the file using the following URL: https://www.googleapis.com/drive/v3/files/${FileId}?alt=media&supportsAllDrives=true.
The scope for the accessToken is 'https://www.googleapis.com/auth/drive.file'. When I attempt to retrieve the file using the main account (in which the file exists), everything works fine. However, if I want to retrieve the file from another account (where the file is shared with that account), I encounter issue 404.
{
"error": {
"code": 404,
"message": "File not found: 1OQSUO7ObmEavKMXXkxNuG12vffqVi-Gk.",
"errors": [{
"message": "File not found: 1OQSUO7ObmEavKMXXkxNuG12vffqVi-Gk.",
"domain": "global",
"reason": "notFound",
"location": "fileId",
"locationType": "parameter"
}]
}
}
Is it possible to obtain a file without the scope 'https://www.googleapis.com/auth/drive', only with 'https://www.googleapis.com/auth/drive.file'?
Upvotes: 5
Views: 3314
Reputation: 76
From the Google oAuth2 docs, https://www.googleapis.com/auth/drive.file
is granted access to See, edit, create, and delete only the specific Google Drive files you use with this app.
which might refer that you can only access all files created by your web app/mobile app not the ones created outside of it, e.g uploaded manually into Google Drive or from other applications.
Tried to reproduce your case via the Try-it-out sandbox of drive API and I got a File not found
error when I ran the file.get
with the https://www.googleapis.com/auth/drive.file
scope on the file, using an access-token
from the very account that uploaded it.
Looks like you have to access the file with the https://www.googleapis.com/auth/drive
scope however if its not with the alt=media
, the https://www.googleapis.com/auth/drive.metadata
and https://www.googleapis.com/auth/drive.metadata.readonly
scopes is enough to access the file.
Other questions: Google Drive api scope and file access (drive vs drive.files)
Upvotes: 5