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

开发网站集成Discord OAuth2时遭遇unsupported_grant_type错误求助

解决Discord OAuth2的unsupported_grant_type错误

你的问题出在axios请求的参数传递方式上:axios的POST请求中,应该用data字段来传递请求体内容,而不是body。这会导致Discord服务器无法正确解析你发送的grant_type参数,从而返回unsupported_grant_type错误。

修正后的代码如下:

function getToken(code) {
    const data = new URLSearchParams({
        client_id: 'ops',
        client_secret: 'ops',
        code: code,
        grant_type: 'authorization_code',
        redirect_uri: 'http://localhost:5500/callback',
        scope: 'identify'
    })
    axios({
        url: 'https://discord.com/api/oauth2/token',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: data.toString() // 替换原有的body字段为data
    }).then(response => {
        return response.data
    })
}

另外再检查几个关键点:

  • 确保redirect_uri和你在Discord开发者平台中配置的完全一致(包括协议、域名、端口、路径)
  • 确认client_id和client_secret是Discord应用的正确凭据
  • 确保grant_type的值确实是authorization_code,没有拼写错误

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 19:35:24