Google Drive REST API Get file returns 404 with scope “drive.file” only
Google Drive REST API Get file returns 404 with scope “drive.file” only
I'm using google drive REST API V3 to access the file. The basic api url is:
https://www.googleapis.com/drive/v3/files/fileid
And the header contains key: Authorization with Bearer access token obtained from oauth.
However, if you create an normal google doc, this works. the response is:
"id": "1v3V0BWcWtYu_K9OLm1rffHA3vj5Bz8SY-0-JpU7CiEc",
"name": "test",
"mimeType": "application/vnd.google-apps.document",
"parents": [
"0AP75Wn-e9WDqUk9PVA"
]
But if I created a google doc from google template, this returns 404. see below:
"error":
"errors": [
"domain": "global",
"reason": "notFound",
"message": "File not found: 14gHUCFTrwHaoZ88Kr0Qnn8OsUdzcU037GK7v-JI9L1I.",
"locationType": "parameter",
"location": "fileId"
],
"code": 404,
"message": "File not found: 14gHUCFTrwHaoZ88Kr0Qnn8OsUdzcU037GK7v-JI9L1I."
That's the point of the
drive.file
scope... from the API, you can only access files that have been created or open with...
'd an application on the same Google Cloud Project. Also, you don't show the code you're using that generates that error - consider showing it.– tehhowch
Aug 22 at 15:18
drive.file
open with...
2 Answers
2
Somehow this is not the case. I created a google doc using the resume template. I obtained the fileID and run it against files.get. I got a 200 response:
"kind": "drive#file",
"id": "1y1h2vHYwrb57O-ein7VhqMwwJKtr4pP4N4bBow7-vus",
"name": "resumeTemplate",
"mimeType": "application/vnd.google-apps.document"
BTW, the URI requst for files.get
is
files.get
https://www.googleapis.com/drive/v3/files/fileId
not
https://www.googleapis.com/drive/v3/files/
Thanks for reply, yes, I was using the correct api, with fileId. I'm not sure how this comes. But that happened to me. Also not just my account, I tested with my company's account, that also happened to me. I'm using postman to test this.
– cairabbit
Jul 24 at 19:58
I did a bit test and found that the "drive.file" scope actually has some problem with getting file metadata/content. From the documentation, the "drive.file" allow the app to access the file that created by this app, or user explicitly open the file with this app, from from drive or from google doc. When I testing this, actually this doesn't work as expect. I upload a few files, one of the files can be accessed by my app, but the others not. I remembered when I publish my app, the google drive team reviewed my app and rejected a few times with the scope, finially the app passed review with "drive.file" scope only.
Did anyone encounter same issue?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The wired thing is if I use my addon "Open With --...." to open it once from Google Drive, now this document became accessible from the api.
– cairabbit
Jul 23 at 23:28