I’m working with Node.js and the googleapis package to fetch files from Google Drive API v3. My goal is simple - get the 10 most recently modified files sorted by date.
api.files.list({
corpora: 'user',
pageSize: 10,
orderBy: 'modifiedTime desc',
fields: 'nextPageToken, files(id, name, owners, modifiedTime, mimeType, parents, size, thumbnailLink, webViewLink, originalFilename)'
}, (error, response) => { ... });
The weird thing is that the API returns files from both my personal drive and shared files, but the newest file it shows has a modifiedTime from April 8th 2020. When I check the actual Google Drive website, I can see files from May 15th 2020 that are much newer.
I tried switching corpora to ‘allDrives’ and added the supportsAllDrives parameter, but that didn’t help at all. I also attempted using a query filter but still got the same outdated results.
What’s really strange is that I tested this same request using Google’s API Explorer tool and got identical results - no recent files showing up. But here’s the kicker - if I manually open one of those missing files in my browser first, then suddenly it appears in the API response.
Is there some kind of indexing delay or cache issue with the Drive API? Why would files only show up after viewing them manually?
you hit google’s drive API indexing bug. i’ve seen this tons of times - their indexing lags behind, especially for files that haven’t been accessed recently. add includeItemsFromAllDrives: true to your existing params. it usually forces a fresh index lookup.
This happens because of how Google Drive’s API handles file visibility. The Drive API only shows files that were recently ‘touched’ by the indexing system. When you view a file in your browser, it triggers an index update for that file - that’s why it suddenly shows up in your API results. Try adding q: 'trashed=false' to your request. This forces the API to do a full search instead of using the cached index. I ran into this exact problem last year building a backup tool, and this fix solved the missing files issue completely.
Had the same issue building a file sync app. Google Drive caches file metadata, so files you haven’t accessed recently won’t show up in standard listing calls - they’re not in the “active” index. I fixed it by ditching files.list and using search instead. Try adding a query parameter like q: 'modifiedTime > "2020-05-01T00:00:00"' with your orderBy. This forces the API to actually search your files instead of returning cached results. That thing where files appear after you view them manually? It’s a known quirk. Opening files in the web interface “refreshes” their API visibility status. Annoying but predictable once you know what’s happening.