Why does my app still see deleted Google Drive files?

Hey everyone, I’m stuck with a weird Google Drive API problem. I made this web form that lets users upload stuff to a shared Drive folder. It’s all set up with a service account that has editor access.

Here’s the thing: when I delete files or folders as the owner in the Drive itself, they’re gone. Like, totally gone - not even in the Trash. But when I use the API to check, those deleted items still show up in the list!

I’m scratching my head here. Is this because of some permission thing? Or maybe deleting as the owner doesn’t affect what the service account sees? I looked through the API docs, but I can’t find any way to refresh the service account’s view.

Do I have to manually delete everything through the API for the service account to see the changes? Any ideas would be super helpful!

yo mike, that’s a weird one for sure. i’ve seen similar stuff with drive before. maybe try using the ‘trashed’ parameter when listing files? sometimes the api doesn’t update as fast as the web interface. also, double-check your service account permissions - they might be caching old data or somethin. good luck man!

I’ve run into this issue before with Google Drive API. It’s likely due to caching on the API side. One solution that worked for me was implementing exponential backoff and retry logic in my app. Essentially, if the API still shows deleted files, wait a bit and try again. Start with a short delay (say, 5 seconds) and double it with each retry.

Another approach is to use the ‘trashed’ query parameter when listing files. This way, you can filter out items that have been moved to trash but not yet fully deleted from the API’s perspective.

If these don’t work, you might need to implement a manual refresh mechanism in your app. This could involve periodically clearing your local cache and re-fetching the entire file list from the API.

Remember, Google Drive’s eventual consistency model means changes don’t always propagate instantly across all systems.

I’ve encountered this issue before, and it can be frustrating. In my experience, there’s often a delay between when files are deleted in the Drive interface and when those changes propagate to the API. This is especially true for service accounts.

One approach that worked for me was implementing a periodic refresh mechanism in my app. I set up a background task that runs every few hours to re-sync the file list. This helped keep things more up-to-date.

Another thing to consider is the ‘fields’ parameter when making API requests. Sometimes, requesting only specific fields can lead to cached responses. Try requesting all fields or at least include ‘trashed’ in your requests.

Lastly, if you’re dealing with a large number of files, you might want to look into using change tokens and the Drive API’s changes.list method. This can be more efficient for tracking deletions and other changes over time.

Hope this helps! Let me know if you need any clarification on these suggestions.