如何将 pydrive 与服务帐户连接

How to connect pydrive with an Service Account

有没有人有任何示例或文档说明如何将来自 Google 驱动器 API 的服务帐户连接到 pydrive。我设法用 auth2 客户端做到了。

显然这应该有效,但它不起作用:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from oauth2client.service_account import ServiceAccountCredentials

gauth = GoogleAuth()
scope = ["https://www.googleapis.com/auth/drive"]
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_FILE, scope)
drive = GoogleDrive(gauth)

更新:错误是由 google IAM 中缺少某些权限引起的。