2
votes

My application has scopes drive.file, drive.readonly and drive.metadata.readonly. Using https://github.com/googleapis/google-api-php-client v2.2.2

It works fine fetching files when authenticated as a Google Drive user, but only when those files are owned by another user (or the same user).

Files stored on a Shared Drive (G Suite Business feature) and shared with the user result in a 404 error:

 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "File not found: 1gasqkgWcabla8sksT5FUtZGzlfIwGbc_aI4g2gl9bla.",
    "locationType": "parameter",
    "location": "fileId"
   }
  ],
  "code": 404,
  "message": "File not found: 1gasqkgWcabla8sksT5FUtZGzlfIwGbc_aI4g2gl9bla."
 }

I have verified that the file in question is indeed readable by that user via Drive/Docs etc.

I have been into the API Console and checked the "Shared Drives support" under Drive UI integration - this made no difference. Neither did it help to add the wider 'drive' scope.

1
I've just tried and for me is working just fine maybe is a sharing issue. How have you shared. Try to visit the page drive.google.com/file/d/1gasqkgWcabla8sksT5FUtZGzlfIwGbc_aI4g2gl9bla. with the account that you have shared to. Also make sure that the ID you are using is the correct one. From the official documentation your ID should not have a dot (".").Raserhin
I've definitely confirmed that the user account can open the file in question. The dot is just the end of the error message, the actual ID used is without dot. The code and flow is working for many users, until one noticed that they could only open files from personal drives. I have now reproduced and confirmed the problem, it seems to be specific to shared drives.Dan

1 Answers

2
votes

After testing I found the same issue.

When I tried to get a file from a Shared Drive with the following HTTP Request

GET /drive/v3/files/<ID-file> HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>

I got the same error as you did:

{
  "error": {
    "code": 404, 
    "message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.", 
    "errors": [
      {
        "locationType": "parameter", 
        "domain": "global", 
        "message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.", 
        "reason": "notFound", 
        "location": "fileId"
      }
    ]
  }
}

But upon reading the documentation it's clear that you need to include the supportsAllDrives paramater to the HTTP request.

So now adding supportsAllDrives=true my request is the following:

GET /drive/v3/files/<File ID>?supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>>

And then I got to retrieve the file in the response:

{
  "mimeType": "image/jpeg", 
  "kind": "drive#file", 
  "name": "file.jpg", 
  "driveId": "<Drive Id>", 
  "teamDriveId": "<Team Drive ID>", 
  "id": "<File ID>"
}