Spotify API返回{“error”:“unsupported_grant_type”,“error_description”:“grant_type parameter is missing”}刷新令牌的发布请求(Ruby)

zsbz8rwp  于 5个月前  发布在  Ruby
关注(0)|答案(1)|浏览(62)

我正在调用Spotify API获取刷新令牌,但一致地获取方法{“error”:“unsupported_grant_type”,“error_description”:“grant_type parameter is missing”},即使我的代码读取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)

字符串

nr7wwzry

nr7wwzry1#

刷新令牌的请求必须经过授权:

@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'],
  }
)

字符串

相关问题