【发布时间】: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', [])
我(认为我)理解的:
我不明白的:
- 通过阅读文档,我怎么知道
files是一种方法? -
list也一样; -
execute()是什么?通过阅读文档我如何知道如何使用它? -
get()的同样问题 - 在哪里可以找到要传递给
get()的参数的解释?
顺便说一句,我认为execute() 执行请求,get() 发出 HTTP 获取请求。但是,我想从文档中了解它,以便我可以正确使用它们。
【问题讨论】: