You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python获取Google OAuth凭证失败:未生成credentials.json及密钥错误

解决Google OAuth凭证生成时的KeyError: 'client_secret'问题

你的问题根源很明确:当前的client_secret_NNNN.json文件缺少client_secret字段,而google-oauthlib-tool在OAuth2授权流程中必须用到这个参数,所以抛出了KeyError。

具体解决步骤:

  • 打开Google Cloud Console,进入你的项目personal-stuff-54a54
  • 导航到APIs & Services > Credentials页面
  • 在"OAuth 2.0 Client IDs"列表中,找到你之前创建的「Installed application」类型的客户端ID
  • 点击该条目右侧的「Download JSON」按钮,重新下载完整的客户端密钥文件
  • 用新下载的文件替换你当前c:\temp\client_secret_NNNN.json文件,确认新文件里包含client_secret键值对(类似"client_secret": "xxxxxx...")
  • 重新运行你原来的命令:
    google-oauthlib-tool --client-secrets c:\temp\client_secret_NNNN.json --credentials c:\temp\credentials.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save
    

补充说明:

有时候如果创建OAuth客户端ID时选错了类型(比如选了Web应用而不是Installed application),下载的JSON文件也会缺少client_secret字段。确保你创建的是Installed application类型,这样生成的密钥文件才会包含完整的OAuth2所需参数。

内容的提问来源于stack exchange,提问作者Konstantin Konopko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:16:48