python - Google身份验证问题: Authorized user info was not in the expected format,缺少字段refresh_token

标签 python google-oauth

我正在尝试使用 Python Google API,但在使用 https://developers.google.com/people/quickstart/python#configure_the_sample 中的 Google 快速入门示例时遇到问题,按原样。当我第一次运行这个示例时,它会打开 Web 浏览器,允许我进行身份验证,并且它工作得很好。但是,如果我再次运行脚本,它不会进行身份验证,而是尝试使用保存在 token.json 中的 token ,并且失败并显示:

Traceback (most recent call last):
  File "/home/thomas/test.py", line 58, in <module>
    main()
  File "/home/thomas/test.py", line 24, in main
    creds = Credentials.from_authorized_user_file('token.json', SCOPES)
  File "/home/thomas/.local/lib/python3.10/site-packages/google/oauth2/credentials.py", line 440, in from_authorized_user_file
    return cls.from_authorized_user_info(data, scopes)
  File "/home/thomas/.local/lib/python3.10/site-packages/google/oauth2/credentials.py", line 390, in from_authorized_user_info
    raise ValueError(
ValueError: Authorized user info was not in the expected format, missing fields refresh_token.

我错过了什么?

最佳答案

我发现了问题:我在 Google Cloud 控制台中的 OAuth key 被配置为“网络应用程序”OAuth key ,而它本应是“桌面应用程序” key 。解决了这个问题后,一切都运行良好。

关于python - Google身份验证问题: Authorized user info was not in the expected format,缺少字段refresh_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74958898/

相关文章:

python - 尝试在 Python 中制作 JSON Schema 验证器以设置默认值

python - Flask 上传中的类型错误 : storage must be a werkzeug. FileStorage

python - 使用 Python 解析 IFF 样式数据

google-chrome-extension - 运行 chrome 扩展的 identity.getAuthToken 时出现错误 'Service has been disabled for this account'

oauth-2.0 - 此应用暂时禁用使用 Google 登录的功能

python - 我什么时候应该在我的公共(public) python 库中停止对 python2.4 的支持?

python - LSTM 模型在第一个 epoch 后的 val_acc 为 1.0?

ios - Google Plus SDK 不刷新 token (iOS)

javascript - 使用 Passport 进行谷歌身份验证: Unable to force the user to pick an account again when he tries to sign-in after the first time

javascript - Google Sheets API 在未登录的情况下将行追加到电子表格时抛出 401 错误