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

使用Google OAuth2.0授权码获取令牌时遇unsupported_grant_type错误求助

解决Google OAuth2.0获取令牌时的unsupported_grant_type错误

你的问题出在curl请求的--data参数格式上:参数里的换行和多余空格导致Google OAuth服务器无法正确解析grant_type参数,所以返回了Invalid grant_type: 的错误提示。

修正后的curl命令

把--data里的所有参数合并为一行,去掉换行和不必要的空格:

curl --location 'https://oauth2.googleapis.com/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'code=4/0AcvDMrAjHZ9AeAhiQiE533rWoe6Hk4gmetvjfv-cY6nXMaaFB8BoVrxL-9-2ZLqjfMh50A&client_id=<client id>&client_secret=<client secret>&redirect_uri=http://localhost&grant_type=authorization_code'

额外注意事项

  • 确保替换<client id>和<client secret>为你在Google控制台获取的真实值,不要保留尖括号
  • 授权码是一次性的,如果之前用过这个授权码,需要重新从授权URL获取新的授权码
  • 检查redirect_uri必须和Google控制台配置的完全一致,包括协议(http/https)和端口(如果有)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 20:40:58