【问题标题】:Unable to authenticate Google API with Oauth2无法使用 Oauth2 对 Google API 进行身份验证
【发布时间】:2016-03-30 18:04:41
【问题描述】:

我有一个 Python 脚本,我已授权它访问 Google 电子表格。但是现在当我运行它时,它会抛出异常:

oauth2client.client.AccessTokenRefreshError: invalid_client: The OAuth client was not found.

我的验证码如下:

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('myapp-credentials.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(
    json_key['client_email'],
    json_key['private_key'], scope)
gc = gspread.authorize(credentials)

我没有更改帐户中的任何内容,所以我不知道为什么它会突然停止工作。如果我登录https://console.developers.google.com/apis/credentials,我看到该应用程序仍在注册。如何诊断并重新启用其访问权限?不幸的是,谷歌搜索这个错误发现了许多潜在的原因。

【问题讨论】:

    标签: python google-api google-api-python-client


    【解决方案1】:

    截至 2016 年 2 月 5 日,类 SignedJwtAssertionCredentials 已成为 removed from the source code,其功能已替换为 ServiceAccountCredentials。这可能会导致您的错误。

    您似乎想要使用类似以下的内容来生成您的credentials

    credentials = ServiceAccountCredentials.from_json_keyfile_name('myapp-credentials.json', scope)
    

    这个Github issue thread 也可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 2022-11-03
      • 1970-01-01
      • 2012-11-20
      • 2021-01-16
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多