我试图让我的应用程序通过他们的Authorization Code Flow登录Spotify。我能设法得到一个访问令牌时从Spotify的接收授权code
在初始授权步骤,但收到以下错误:Spotify授权代码
{"error":"invalid_client","error_description":"Invalid client"}
我的代码如下:
# Callback from Spotify Authorization
get '/auth/spotify/callback' do
session[:code] = params[:code]
redirect to '/refresh'
end
然后,我张贴如下:
get '/refresh' do
uri = URI('https://accounts.spotify.com/api/token')
resp = Net::HTTP.post(uri,
{
"grant_type" => "authorization_code",
"code" => session[:code].to_s,
"redirect_uri" => "http://localhost:4567/auth/spotify/callback",
"client_id" => client_id,
"client_secret" => client_secret
}.to_json
)
"#{resp.body}"
end
任何帮助,将不胜感激
编辑:我也试过使用PostMan POST上述相同的参数,但收到相同的错误消息
这看起来像一个非常典型的OAuth2流程的正确方法。为了简单起见,您可能需要考虑使用[oauth2](https://github.com/intridea/oauth2)之类的内容。 – coreyward