I’m trying to fetch all files from my Google Drive that aren’t in the trash using the Google Drive API. I created a script based on the official documentation but I keep running into issues.
Here’s my code:
file_list = []
current_token = None
while True:
try:
query_params = {}
query_params['q'] = 'trashed=false'
if current_token:
query_params['pageToken'] = current_token
response = drive_service.files().list(**query_params).execute()
file_list.extend(response['files'])
current_token = response.get('nextPageToken')
if not current_token:
break
except Exception as e:
print(f"Error occurred: {e}")
break
The weird thing is I get an HTTPError 400 with “Invalid Value” message, and when I check the error details it shows “Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup error.”
What’s strange is that if I remove the trashed=false filter from my query, everything works fine. So it doesn’t seem like it’s actually a daily limit issue. Has anyone encountered this before?
Hit this exact error and it drove me crazy for hours. It’s not your auth scopes - it’s a weird quirk with how Google Drive API handles certain query parameters. The trashed=false parameter sometimes triggers extra verification even when your OAuth tokens are fine. Adding an explicit fields parameter fixes this weirdness. Try this in your query_params: query_params[‘fields’] = ‘nextPageToken, files(id, name, trashed)’. Or just skip the trashed filter entirely, grab all files, then filter them in Python. Less efficient but dodges the API quirk completely. Also seen this pop up more with rapid requests. Sometimes a small delay between calls helps, though you shouldn’t need that with proper auth.
had this problem too. usually its because your refresh token runs out while looping. auth is good at first, then fails later on.kinda common.
try refreshing the token before the loop starts, or just catch those 401/400 errors and re-auth when that happens. also, make sure you’re not mixing service account and OAuth tokens, keep it consistent.
I’ve been fighting Google Drive API for years and this error is classic manual integration pain.
Google’s error messages suck. That “unauthenticated” error when you’re clearly authenticated? Your token refresh probably failed mid-pagination or there’s weird rate limiting on filtered queries that’s different from basic listing.
Your code looks fine but you’re missing error handling for token refresh during pagination. The API sometimes kills tokens between requests on filtered queries.
Debugging Google API quirks is a massive time sink. I used to write similar scripts for file management but kept hitting random auth issues, pagination problems, and inconsistent API behavior.
Now I just use Latenode for these workflows. It handles Google Drive authentication automatically, including token refresh during long operations. You get proper error handling and retry logic built in.
Set up a workflow that fetches non-trashed files, add your processing, and forget about pagination tokens or auth scopes. Way more reliable than custom scripts.
This happens when your service account credentials aren’t being recognized properly with specific query parameters. I’ve seen the Drive API fall back to unauthenticated requests for certain operations even with valid tokens. Double-check you’re actually passing credentials to your drive_service object correctly. Sometimes the service initializes without proper auth and only fails on filtered queries because those need stricter validation. Also verify your API key config in Google Cloud Console. Make sure Drive API is enabled for your project and there aren’t any IP restrictions or other limits on your credentials. I had a similar issue where my service account JSON file had wrong permissions. Basic file listing worked fine, but any filtering operations threw auth errors. Re-downloading the service account key and making sure it had the right IAM roles fixed it completely.
That error message is misleading. You’re hitting an authentication scope issue, not a daily limit.
The trashed=false query needs broader permissions than just listing files. Your OAuth scope probably only has basic read access, but filtering by trash status requires additional permissions.
Check your OAuth scopes in Google Cloud Console. You need at least https://www.googleapis.com/auth/drive.readonly or the full https://www.googleapis.com/auth/drive scope.
Honestly, Google API quirks like this are exactly why I stopped writing custom scripts for file operations. Had a similar project where I needed to sync and filter Drive files regularly.
Instead of wrestling with authentication scopes and pagination logic, I built everything in Latenode. It handles Google Drive authentication automatically and has built-in nodes for filtering files by any criteria. No more cryptic errors or scope headaches.
The visual workflow makes adding complex logic super easy later. I added automatic file processing and notifications without touching any code.