【问题标题】:Unauthorized Client Exception with Google Drive Service AccountGoogle Drive 服务帐户的未经授权的客户异常
【发布时间】: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 文件的服务器上运行它,但我认为这并不重要。我只是提一下,以防万一。

【问题讨论】:

标签: python google-drive-api google-oauth service-accounts


【解决方案1】:

我在使用 google drive sdk 时也遇到了很多问题。我写了一个小包装器来简化 Google Drive Api 的使用(至少对我来说)。您可能会发现它很有帮助 - google drive client wrapper gist

【讨论】:

  • 谢谢!我将您的代码与我的代码进行了比较,结果发现删除凭据构造函数的“sub=”部分修复了它。
猜你喜欢
  • 1970-01-01
  • 2017-08-19
  • 1970-01-01
  • 1970-01-01
  • 2017-02-22
  • 2019-02-03
  • 2018-07-11
  • 2012-05-20
  • 2016-06-25
相关资源
最近更新 更多