Python Google Drive API returns no files despite successful authentication

I’m having trouble with the Google Drive API using Python. My authentication works fine and I can connect to the service, but when I try to fetch files from my drive, I always get an empty result set.

from googleapiclient.discovery import build

def check_drive_files(drive_client):
    # drive_client is my custom wrapper that handles authentication
    api_service = drive_client.get_service('drive', drive_client.auth_token, 'v3')
    
    # Try to get folders from root directory
    response = api_service.files().list(
        q="'root' in parents and mimeType='application/vnd.google-apps.folder'",
        spaces='drive',
        fields='nextPageToken, files(id, name)'
    ).execute()
    
    file_list = response.get('files', [])
    
    if len(file_list) == 0:
        print(f'Empty response received: {response}')
        return False
    
    return True

The response I get is always {'files': []} even though I know there are folders in my root directory. I’ve also tried searching for specific folder names but still get empty results. My authentication scope is set to https://www.googleapis.com/auth/drive.file. Could this be a permissions issue or am I missing something in my query?

The scope you’re using is definitely the culprit here. I ran into this exact same issue about six months ago and spent way too much time debugging my queries before realizing the problem was with permissions. The https://www.googleapis.com/auth/drive.file scope only allows access to files that your application has created or that the user has explicitly opened with your app through the picker API. It won’t show existing files that were created outside of your application context. You need to switch to https://www.googleapis.com/auth/drive.readonly for read access to all files, or https://www.googleapis.com/auth/drive for full access. After changing the scope, make sure to delete any cached credentials and re-authenticate completely, otherwise you’ll still be working with the limited permissions from your original authorization.

Your authentication scope is too restrictive for what you’re trying to accomplish. The drive.file scope has very limited visibility and will only return files that were specifically created by your application or explicitly selected through Google’s file picker interface. Since you’re querying for existing folders in your root directory that weren’t created by your app, they simply won’t appear in the results. I encountered this same frustration when building a backup utility last year - everything seemed to work perfectly until I realized the API was essentially blind to most of my actual files. You’ll need to update your scope to either drive.readonly or the full drive scope depending on whether you need write access. Don’t forget to clear your existing credentials after making this change, as the old token will still carry the limited permissions even after updating your code.

for sure it’s a scope issue! i had a similar problem a while back, and it really messed me up. the drive.file scope is honestly super limited, only shows files created by your app or opened via the picker. changing to drive.readonly should help, but remember to revoke the old token first!