使用httpkit调用Spotify API遇400错误:仅支持Bearer认证的解决方法
问题解决:Spotify API返回"Only valid bearer authentication supported"
错误的核心原因是Authorization请求头格式不符合Spotify API要求。Spotify要求Bearer认证的格式为Bearer {access_token},而你的代码中直接将access_token作为Authorization头的值,缺少了Bearer 前缀。
修改get-me函数中的headers配置即可解决:
(defn get-me [token] @(client/request {:url "https://api.spotify.com/v1/me" :method :get :headers {"Authorization" (str "Bearer " token) ; 添加Bearer前缀 "Accept" "application/json" "Content-Type" "application/json"}}))
额外检查项:
- 确保从
res中读取的access_token是正确的纯字符串,没有被多余的引号包裹 - 确认当前token处于有效期内,未过期
内容的提问来源于stack exchange,提问作者Jack Gee
相关产品推荐
相关产品推荐

