【问题标题】:Incomplete Google Drive REST API results for Team Drive files团队云端硬盘文件的 Google Drive REST API 结果不完整
【发布时间】:2017-09-12 15:36:33
【问题描述】:

问题

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

由于我使用的凭据(在云控制台中设置为 Owner),我(认为?)对团队云端硬盘的文件和文件夹拥有完全权限。

不过,我的问题是,当我查询 REST API 以获取给定团队驱动器的文件列表时,结果不符合 documentation。返回的文件对象仅包含 5 个字段:

  • kind, name, id, mimeType, teamDriveId

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

下面是我用来查询 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,这显然不是预期的输出。

我没有获得完整的预期数据的原因有什么见解吗?

【问题讨论】:

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


    【解决方案1】:

    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"
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多