【问题标题】:Syntax of Google Drive API requests in PythonPython 中 Google Drive API 请求的语法
【发布时间】:2018-06-01 19:10:07
【问题描述】:

第一次尝试将 Google Drive API 与 Python 结合使用。

此脚本列出了我的 Google Drive 文件夹中的文件。

from __future__ import print_function

from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools

SCOPES = 'https://www.googleapis.com/auth/drive.readonly.metadata'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_id.json', SCOPES)
    creds = tools.run_flow(flow, store)
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))

# List files Google Drive
files = DRIVE.files().list().execute().get('files', [])
for f in files:
    print(f['name'], f['mimeType'], f['sharedWithMeTime'])

通过docs,我对这里的语法感到困惑:

files = DRIVE.files().list().execute().get('files', [])

我(认为我)理解的:

  1. DRIVE 是驱动实例;
  2. 文件如here 所述;
  3. 可以在文件上调用列表,如here 所述;

我不明白的:

  1. 通过阅读文档,我怎么知道files 是一种方法?
  2. list 也一样;
  3. execute() 是什么?通过阅读文档我如何知道如何使用它?
  4. get() 的同样问题
  5. 在哪里可以找到要传递给get() 的参数的解释?

顺便说一句,我认为execute() 执行请求,get() 发出 HTTP 获取请求。但是,我想从文档中了解它,以便我可以正确使用它们。

【问题讨论】:

    标签: python google-drive-api


    【解决方案1】:

    我建议从 Python Quickstart 开始,因为您的当前似乎正在混合使用 files.list 和 files.get。然后你有官方的Python library reference for Drive API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-02
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      相关资源
      最近更新 更多