google-drive-api - 团队云端硬盘文件的 Google 云端硬盘 REST API 结果不完整

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

问题

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

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

尽管如此,我的问题是,当我查询 REST API 查找给定团队云端硬盘的文件列表时,结果不符合 documentation 。返回的文件对象仅包含 5 个字段,分别是:

  • 种类名称idmimeTypeteamDriveId

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

下面是我用来查询 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)

对于给定的团队云端硬盘,输出为

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

这显然不是 docs 的预期输出.

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

最佳答案

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

关于google-drive-api - 团队云端硬盘文件的 Google 云端硬盘 REST API 结果不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46180485/

相关文章:

java - GoogleApiClient 尚未连接,即使调用了 onConnected 并且我正在 onCreate 中创建我的 GoogleApiClient

ruby-on-rails - 使用 GAN 发布者 ID 访问 google shopping api 的 Ruby 示例

google-cloud-platform - GCP BigQuery 如何通过 python api 将到期日期设置为表

python - 直接从 Python 提交 Google Cloud ML Engine 作业

cross-browser - 如何使用 html 音频标签播放 google drive mp3 文件?

python - Google 驱动器多线程移动文件 PYTHON

java - 创建帐户按钮始终会转到登录 Gmail 帐户的浏览器。它怎么总是会请求谷歌的许可呢?

python - 使用 Google Sheets API 将 Google Sheet 文档发布到网络

google-drive-api - 在运行时在 Google Colab 中重新验证或删除验证 Pydrive

python - 如何测试基于 appengine/drive/google api 的应用程序?