I’m having trouble accessing file information from Team Drives using the Google Drive API. My current method works perfectly for personal files and files shared directly with me, but fails when trying to get metadata for files located in Team Drives.
Here’s my current approach:
def fetch_document_details(document_id):
drive_service = get_authenticated_service()
file_info = drive_service.files().get(
fileId=document_id,
fields="id, name, md5Checksum, webViewLink"
).execute()
print(file_info)
return file_info
if __name__ == "__main__":
fetch_document_details('SAMPLE_FILE_ID')
When I run this code with a Team Drive file ID, I get a 404 error saying the file cannot be found. However, I can see these files when I use the list API with the corpora='allDrives' parameter.
Is there a similar parameter I need to add to the get request to access Team Drive files? Any help would be appreciated.
Had this exact issue last year when we switched to Shared Drives. Google Drive API handles Shared Drives differently than personal drives. You’ll need supportsAllDrives=True like others said, but also check your OAuth scopes - some restricted scopes don’t work with Shared Drives. If you’re still getting 404s after fixing the API call, it’s probably a permissions issue. Make sure you actually have access to that Shared Drive first.
The API treats Shared Drives (formerly Team Drives) as separate entities that need explicit access. When you call files().get() without the right flags, it only searches your personal drive. Add supportsAllDrives=True to your get request - this tells the API to include Shared Drive content too. Without it, the API defaults to My Drive only for backward compatibility. I hit this same issue when migrating old code that worked fine until we started using Shared Drives heavily. Easy fix once you realize the API needs explicit permission for collaborative spaces.
yeah, you need to add supportsAllDrives=True in your get() call. team drives won’t work otherwise; you’ll just keep gettin 404 even tho the files are there. and also using includeItemsFromAllDrives=True can help too.
This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.