Ruby on rails 使用rspotifgem和Spotify在URI中包含了一个查询sting,这使得它成为未经批准的源rails和heroku

Ruby on rails 使用rspotifgem和Spotify在URI中包含了一个查询sting,这使得它成为未经批准的源rails和heroku,ruby-on-rails,ruby,heroku,spotify,Ruby On Rails,Ruby,Heroku,Spotify,所以我使用RSpotify让用户批准我们的应用程序,然后重定向到我们的网站。问题在于,当Spotify重定向时,它包含了一个查询字符串。这是在抛弃它,它认为URI不是一个经过批准的源 在我把我的网站放在heroku之前,一切都正常 以下是错误: +00:00 app[web.1]: I, [2020-02-17T12:09:24.460751 #4] INFO -- omniauth: (spotify) Request phase initiated. 2020-02-17T12:0

所以我使用RSpotify让用户批准我们的应用程序,然后重定向到我们的网站。问题在于,当Spotify重定向时,它包含了一个查询字符串。这是在抛弃它,它认为URI不是一个经过批准的源

在我把我的网站放在heroku之前,一切都正常

以下是错误:

    +00:00 app[web.1]: I, [2020-02-17T12:09:24.460751 #4]  INFO -- omniauth: (spotify) Request phase initiated.
2020-02-17T12:09:24.464829+00:00 heroku[router]: at=info method=GET path="/auth/spotify" host=www.themixtapeproj.com request_id=cf73be87-9844-4b18-ba0b-518e4046676a fwd="47.17.47.4" dyno=web.1 connect=1ms service=4ms status=302 bytes=1463 protocol=http
2020-02-17T12:09:24.663083+00:00 heroku[router]: at=info method=GET path="/auth/spotify/callback?code=AQArRuRXYD_gebJVlU1Ljht_4XDFr_1dAAqlI-20Tq5504JFdP92MpRIDoNFVvBpS4xPPAqrdAJlooCTZA3yLPeUFKk5W1SE9KkLFsDp--1tIm2Vt2Y6_jrNWmDsBvWvBkuSlBbXaBW5gti8sbIHlMCHXt8MDP82l2BTduVDgjStbSuFt8SoWo8BLeYT8pc68LUs7eFqoJoww-ywkc0gLz1V7tzpEkOkn6I8N7-LRTr9cXQt_kJfQdnpsbiQ0KSn2g&state=2d5bbf3deccf88d92d68f5022475522564622cfc77104794" host=www.themixtapeproj.com request_id=f8ef1adc-0693-4ab5-bf63-f23b63b3ee1b fwd="47.17.47.4" dyno=web.1 connect=1ms service=50ms status=302 bytes=769 protocol=http
2020-02-17T12:09:24.612879+00:00 app[web.1]: I, [2020-02-17T12:09:24.612791 #4]  INFO -- : [f8ef1adc-0693-4ab5-bf63-f23b63b3ee1b] Started GET "/auth/spotify/callback?code=AQArRuRXYD_gebJVlU1Ljht_4XDFr_1dAAqlI-20Tq5504JFdP92MpRIDoNFVvBpS4xPPAqrdAJlooCTZA3yLPeUFKk5W1SE9KkLFsDp--1tIm2Vt2Y6_jrNWmDsBvWvBkuSlBbXaBW5gti8sbIHlMCHXt8MDP82l2BTduVDgjStbSuFt8SoWo8BLeYT8pc68LUs7eFqoJoww-ywkc0gLz1V7tzpEkOkn6I8N7-LRTr9cXQt_kJfQdnpsbiQ0KSn2g&state=2d5bbf3deccf88d92d68f5022475522564622cfc77104794" for 47.17.47.4 at 2020-02-17 12:09:24 +0000
2020-02-17T12:09:24.613242+00:00 app[web.1]: I, [2020-02-17T12:09:24.613191 #4]  INFO -- omniauth: (spotify) Callback phase initiated.
2020-02-17T12:09:24.659971+00:00 app[web.1]: E, [2020-02-17T12:09:24.659789 #4] ERROR -- omniauth: (spotify) Authentication failure! invalid_credentials: OAuth2::Error, invalid_grant: Invalid redirect URI
2020-02-17T12:09:24.659978+00:00 app[web.1]: {"error":"invalid_grant","error_description":"Invalid redirect URI"}
2020-02-17T12:09:24.765658+00:00 app[web.1]: I, [2020-02-17T12:09:24.765530 #4]  INFO -- : [bdbf5819-3907-42ba-9d02-6c32137425b5] Started GET "/auth/failure?message=invalid_credentials&origin=http%3A%2F%2Fwww.themixtapeproj.com%2Fmixtapes%2F4&strategy=spotify" for 47.17.47.4 at 2020-02-17 12:09:24 +0000
2020-02-17T12:09:24.766489+00:00 app[web.1]: F, [2020-02-17T12:09:24.766404 #4] FATAL -- : [bdbf5819-3907-42ba-9d02-6c32137425b5]
据我所知,是查询字符串将其抛出。因为我已经批准了

那我该怎么做才能让它工作呢

编辑:这是授权部分(出现在上述错误之前):

结束


用户授予或拒绝权限后要重定向到的URI。此URI需要在注册应用程序时指定的重定向URI白名单中输入。此处的redirect_URI值必须与注册应用程序时输入的其中一个值(包括大写或小写)完全匹配g斜杠,诸如此类。”回调URI中的查询用于什么?这个问题实际上并没有显示对
https://accounts.spotify.com/authorize...
这会启动整个链条,因此很难确定您要做什么。您可以从firebug/web inspector.max中的“网络”选项卡获得它。我已将重定向URI输入到白名单中。不幸的是,这不是他们现在想要做的。(我已经在我的本地服务器上运行了这个功能,但是现在我移动到heroku后它就不工作了。)我将向您展示链的授权部分。感谢您的编辑,但最重要的信息是重定向到
https://accounts.spotify.com/authorize...
已丢失。你在日志里找不到。我不知道你的意思是什么。我正在使用RSpotify,它使用Omniauth。
2020-02-17T15:41:52.150535+00:00 heroku[router]: at=info method=GET path="/auth/spotify" host=www.themixtapeproj.com request_id=2092bd50-787f-4f4f-a3a5-47e8ed29c171 fwd="100.38.116.113" dyno=web.1 connect=0ms service=15ms status=302 bytes=1451 protocol=http
2020-02-17T15:41:52.032671+00:00 heroku[router]: at=info method=GET path="/auth/spotify" host=www.themixtapeproj.com request_id=43b76294-4e0b-4137-9c40-ef0d132d97ed fwd="100.38.116.113" dyno=web.1 connect=13ms service=66ms status=302 bytes=1457 protocol=http
2020-02-17T15:41:52.005375+00:00 app[web.1]: I, [2020-02-17T15:41:52.005256 #4]  INFO -- : [43b76294-4e0b-4137-9c40-ef0d132d97ed] Started GET "/auth/spotify" for 100.38.116.113 at 2020-02-17 15:41:52 +0000
2020-02-17T15:41:52.005965+00:00 app[web.1]: I, [2020-02-17T15:41:52.005846 #4]  INFO -- omniauth: (spotify) Request phase initiated.
2020-02-17T15:41:52.140507+00:00 app[web.1]: I, [2020-02-17T15:41:52.140388 #4]  INFO -- : [2092bd50-787f-4f4f-a3a5-47e8ed29c171] Started GET "/auth/spotify" for 100.38.116.113 at 2020-02-17 15:41:52 +0000 ```





Rails.application.config.middleware.use OmniAuth::Builder do
        spotify_key = ENV['SPOTIFY_KEY']
        spotify_secret = ENV['SPOTIFY_SECRET']
        provider :spotify, spotify_key, spotify_secret, scope: 'playlist-modify-public'
end

def spotify
    spotify_user = RSpotify::User.new(request.env['omniauth.auth'])
    session[:spotify_user] = spotify_user.to_hash
    redirect_to spotify_landing_path