Problem
During the first phase of my Team Drive backup system, I first need to scan files in the given Team Drive in order to determine which files to copy for backup.
I (think?) have full permissions over the files & folders of the Team Drive, due to the credentials I use (set to
Owner
in the cloud console).
Nevertheless, my problem is that when I query the REST API for a file listing of a given Team Drive, the results do not comply with the documentation. The returned file objects only contain 5 fields that are:
kind
,name
,id
,mimeType
,teamDriveId
According to the documentation provided, I should receive a handful more of fields.
Below is the code I use to query the API and the output.
Simplified source
credentials = get_credentials() # retrieves and processes app credentials
drive = get_drive_api(credentials) # get the drive API v3 using httplib2 and discovery
query = drive.files().list(
pageSize = 10,
corpora = 'teamDrive',
supportsTeamDriveItems = True,
includeTeamDrives = True,
teamDriveId = "..."
)
results = query.execute() # contact the REST API
files = results.get('files', [])
for file in files:
print(file)
For the given Team Drive, output is
{
'kind': 'drive#file',
'id': '...',
'name': 'filename',
'mimeType': 'application/vnd.google-apps.document',
'teamDriveId': '...'
}
Which clearly isn't the expected output according to the docs.
Any insights on the reason I do not get the complete expected data ?
With Google Drive API v3 full resources are no longer returned by default. Use the
fields
query parameter to request specific fields to be returned. If left unspecified only a subset of commonly used fields are returned.To fetch all available fields of the resource you can set
fields
to*
.For example: