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

调用Spotify接口获取访问令牌时返回400错误的排查求助

调用Spotify接口获取访问令牌时返回400错误的排查求助

我现在在尝试通过Spotify的接口获取访问令牌,但是一直返回400 Bad Request错误,完全搞不清楚哪里出问题了。

async function getAccessToken(clientId, code) {
    const verifier = localStorage.getItem("verifier");
    const params = new URLSearchParams();
    params.append("client_id", clientId);
    params.append("grant_type", "authorization_code");
    params.append("code", code);
    params.append("redirect_uri", "http://localhost:5173/callback");
    params.append("code_verifier", verifier);

    const result = await fetch("https://accounts.spotify.com/api/token", {
        method: "POST",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        body: params
    });
    
    
    const { access_token } = await result.json();
    return access_token;
}

我已经确认clientId、code还有verifier这些参数都是存在的,但就是找不到问题所在,有没有大佬能帮忙排查一下?

备注:内容来源于stack exchange,提问作者Jerry Zhou

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 16:58:04