我正在调用 Spotify api 来获取刷新令牌,但始终得到方法 {"error":"unsupported_grant_type","error_description":"grant_type 参数丢失"} 即使我的代码显示为
grant_type: 'refresh_token'
并且在阅读文档后不确定该问题,任何帮助将不胜感激!
这是我到目前为止的代码
@response = HTTParty.post("https://accounts.spotify.com/api/token",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {
grant_type: 'refresh_token',
refresh_token: ENV['REFRESH_TOKEN'],
client_id: ENV['CLIENT_ID']
}.to_json)
哎呀,我相信这就是解决方案 - 我未经授权就发送了它
@response = HTTParty.post("https://accounts.spotify.com/api/token", headers: { 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => "Basic #{Base64.strict_encode64("#{ENV['CLIENT_ID']}:#{ENV['CLIENT_SECRET']}")}" }, body: { grant_type: 'refresh_token', refresh_token: ENV['REFRESH_TOKEN'], } ) end