小编Ckn*_*knu的帖子

使用 Drive API 获取文件内容

我正在尝试使用文档中drive().files().get()所述的 v3 方法下载已上传到团队云端硬盘的文件
我可以获得元数据,如文件 ID 和权限,但不知道如何访问实际的二进制内容,例如将其写入文件。有问题的文件是纯文本文件。

这是我正在使用的代码的一部分。

    request = service.files().get(fileId=file_id, supportsTeamDrives=True)
    pprint.pprint(request.to_json())
    response = request.execute()
    pprint.pprint(response)
Run Code Online (Sandbox Code Playgroud)

和响应(来自 pprints)
请求

{
  "uri": "https://www.googleapis.com/drive/v3/files/1CxxxxxxxxxxxxHp?supportsTeamDrives=true&alt=json", 
  "method": "GET",
  "body": null,
  "headers": {
    "accept": "application/json",
    "accept-encoding": "gzip, deflate",
    "user-agent": "google-api-python-client/1.7.8 (gzip)"
  },
  "methodId": "drive.files.get",
  "resumable": null,
  "response_callbacks": [],
  "_in_error_state": false, 
  "body_size": 0,
  "resumable_uri": null, 
  "resumable_progress": 0
}
Run Code Online (Sandbox Code Playgroud)

文件元数据

{
  "uri": "https://www.googleapis.com/drive/v3/files/1CxxxxxxxxxxxxHp?supportsTeamDrives=true&alt=json", 
  "method": "GET",
  "body": null,
  "headers": {
    "accept": "application/json",
    "accept-encoding": "gzip, deflate",
    "user-agent": "google-api-python-client/1.7.8 (gzip)"
  },
  "methodId": "drive.files.get",
  "resumable": null, …
Run Code Online (Sandbox Code Playgroud)

google-drive-api google-api-python-client

5
推荐指数
1
解决办法
3528
查看次数