4

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'?

2 Answers2

3

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)

pilar
  • 46
  • 4
0

I don't think the problem are the scopes you are using, according to Drive documentation, using 'https://www.googleapis.com/auth/drive.file' should be enough to run the query. On the other hand, looking at the error:

"code": 404,
"message": "File not found: 1OQSUO7ObmEavKMXXkxNuG12vffqVi-Gk.",

It seems to me the FileID that was queried has a . at the end of it, which might be the reason the Drive API is throwing the 404 error, keep in mind that File IDs doesn't have special characters at the end. Try to remove the 'dot' at the end of the file ID and let us know if that worked for you! :)

References:

Milagro Sosa
  • 424
  • 1
  • 10
  • I'm 100% sure that there is no 'dot' in the fileId. It was added by Google on their response. Moreover, I tried doing it manually (getting the token and sending a GET request to files.get) and received the same error. Also I checked one more time after your response. – Andrew Mooweek Jun 16 '23 at 15:19
  • That's definitely odd, just checking, have you opened the file previously? I ask because the scope 'https://www.googleapis.com/auth/drive.file' gives you access to the file you have opened before. Also, do you get the same error if you try the scope https://www.googleapis.com/auth/drive?? – Milagro Sosa Jun 16 '23 at 15:28
  • Yes, i`ve opened file. Everything works fine with scope [googleapis.com/auth/drive](https://googleapis.com/auth/drive) – Andrew Mooweek Jun 18 '23 at 23:57