spotify api没有提供令牌,错误401,从httparty获取艺术家

时间:2019-01-30 17:36:02

标签: api spotify httparty

当我试图从Spotify api上的关注艺术家那里获得响应时,我遇到了麻烦。

我正在为此使用httparty:

HTTParty.post('https://accounts.spotify.com/api/token', headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' }, query: { 'client_id' => 'my_client_id', 'client_secret' => 'my_client_secret', 'grant_type' => 'client_credentials', 'redirect_uri' => 'http://0.0.0.0:8080', 'scope' => 'user-follow-read' })

在那之后,我继续:

HTTParty.get('https://api.spotify.com/v1/me/following?type=artist', headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json'}, query: {'Authorization' => 'Bearer my_access_token' })

然后我得到了这个回报:

#<HTTParty::Response:0x3e7dc38 parsed_response={"error"=>{"status"=>401, "message"=>"No token provided"}}, @response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>

我知道出了点问题,但是我不明白是什么。有人可以帮助我吗?

0 个答案:

没有答案