Dan
Dan

Reputation: 1421

Google Drive API - Files stored in a GSuite Shared Drive (only) get a 404 error

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.

Upvotes: 2

Views: 2077

Answers (1)

Raserhin
Raserhin

Reputation: 2686

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>"
}

Upvotes: 3

Related Questions