【发布时间】:2015-06-16 01:11:39
【问题描述】:
我正在尝试使用带有 python 的服务帐户身份验证来设置 Google Drive 应用程序。我已经尝试了我能找到的所有说明,但我无法授权客户。这是我得到的:
CLIENT_EMAIL='<stuff>@developer.gserviceaccount.com'
f = open('<the .p12 file I downloaded from the OAuth section of the credentials page on the developers console>', 'rb')
key = f.read()
credentials = SignedJwtAssertionCredentials(CLIENT_EMAIL, key, scope='https://www.googleapis.com/auth/drive', sub="<the email address of the account owner listed in the permissions page>")
self.http = credentials.authorize(httplib2.Http())
gauth = GoogleAuth()
gauth.credentials = credentials
self.drive = GoogleDrive(gauth)
在后面的代码中,这一行
file_list = self.drive.ListFile({'q': "title = '" + id + '.zip' + "'", 'maxResults': 100}).GetList()
我的代码抛出一个unauthorized client exception。我还尝试将我直接下载的 JSon 中的私钥粘贴到代码中,但这也不起作用。将密钥解码或编码为 base64 不起作用(给我一些格式错误)。有谁知道可能出了什么问题?
我也在一个不是我下载 p12 文件的服务器上运行它,但我认为这并不重要。我只是提一下,以防万一。
【问题讨论】:
-
您的代码看起来有点不对劲。我认为您没有正确授权您的 GoogleDrive 服务developers.google.com/api-client-library/python/auth/…
标签: python google-drive-api google-oauth service-accounts