Team Drive文件的Google Drive REST API结果不完整

时间:2017-09-12 15:36:34

标签: google-drive-api google-api-client google-python-api

问题

在我的Team Drive备份系统的第一阶段,我首先需要扫描给定Team Drive中的文件,以确定要复制哪些文件进行备份。

  

我(想想?)拥有对文件的完全权限。 Team Drive的文件夹,由于我使用的凭据(在云控制台中设置为Owner)。

然而,我的问题是,当我在REST API中查询给定Team Drive的文件列表时,结果不符合documentation。返回的文件对象只包含5个字段:

  • kindnameidmimeTypeteamDriveId

根据提供的文件,我应该收到更多的字段。

以下是我用来查询API和输出的代码。

简化来源

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)

对于给定的Team Drive,输出为

{
  'kind': 'drive#file',
  'id': '...',
  'name': 'filename',
  'mimeType': 'application/vnd.google-apps.document',
  'teamDriveId': '...'
}

根据docs显然不是预期的输出。

有关我无法获得完整预期数据的原因的任何见解?

1 个答案:

答案 0 :(得分:3)

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.

要获取资源的所有可用字段,您可以将fields设置为*

例如:

query = drive.files().list(
    pageSize = 10,
    corpora = 'teamDrive',
    supportsTeamDriveItems = True,
    includeTeamDrives = True,
    teamDriveId = "...",
    fields="*"  # or maybe "files(id,name,capabilities/canShare),nextPageToken"
)
相关问题