Google Drive API returns 404 error when fetching file metadata

I’m running into a strange problem with Google Drive API that’s driving me crazy.

The Setup

I built an app that uses Google Drive API with the file picker. Everything works perfect when I test it with my main Google account. The picker shows all my files and I can grab metadata without any issues.

Here’s the Ruby code I’m using to fetch file details:

require 'google/apis/drive_v3'

service = Google::Apis::DriveV3::DriveService.new
service.client_options.application_name = 'My Drive App'
service.authorization = get_credentials

begin
  file_data = service.get_file(document_id)
  puts file_data.name
  puts file_data.mime_type
rescue Google::Apis::ClientError => e
  puts "Error: #{e.message}"
end

The Problem

When I switch to a different Google account, things fall apart. The file picker still works and shows all the files from that account. But when I try to fetch metadata for any file using the same code, I get a 404 error saying the file doesn’t exist.

I even tested this in Google’s OAuth playground and got the same 404 errors for both accounts, which makes no sense.

My Theory

I’m wondering if this has something to do with a Chrome Web Store app I published earlier. I accidentally made it public as a Drive-enabled app, then quickly removed it and changed the manifest back to normal. Could Google’s servers still have some cached info about my app that’s causing these permission issues?

Has anyone seen this kind of behavior before? I’m really stuck here and would appreciate any ideas.

Had the same issue about six months ago - turned out to be a scope problem that wasn’t obvious at first. The file picker can show files with broader permissions than your API calls actually get. When you’re switching between Google accounts, the auth flow might grant different scopes even though you think you’re requesting the same ones. Double check your OAuth config is asking for drive.readonly at minimum, then verify what scopes you’re actually getting in Google Cloud Console under your project’s OAuth consent screen. Also check if the second account has org restrictions blocking API access even though the picker works fine. Cached app could be it but probably won’t cause account-specific issues like this.

This sounds like a file ownership issue, not an API problem. Your main account works because you own those files directly. The second account can see files in the picker, but it probably doesn’t own them - they’re just shared with it. The Drive API needs specific permissions to read metadata, and view access through sharing isn’t always enough. Check the actual permissions on the failing files using the permissions.list endpoint first. Also make sure both accounts have the same access level to your OAuth app. Enterprise accounts sometimes have extra restrictions that personal accounts don’t have, which could explain why identical code behaves differently.

Weird one but I’ve seen this before. That Chrome Web Store app is probably the issue - Google’s backend takes weeks to clear cached permissions even after removal. Create a completely new OAuth client ID in your Google Cloud project instead of reusing the old one. Also check if your second account has 2FA or workspace restrictions blocking the API calls.