gpt4 book ai didi

ruby-on-rails - Ruby on Rails - SoundCloud OAuth 2 未定义方法 `access_token'

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:41 25 4
gpt4 key购买 nike

我正致力于在 Rails 5 上制作个人 soundcloud 应用程序,但我在使用 OAuth 时遇到了一些问题。我能够重定向到 Soundcloud 的应用程序并授予我的用户权限。当我尝试在 redirect_uri 上交换 token 代码时,出现错误。我在下面包含了我的代码和错误图像。

def connected 

client = Soundcloud.new(:client_id => 'My ID',
:client_secret => 'my secret',
:redirect_uri => "http://localhost:3000/login/soundcloud/callback")

code = params[:code]
value = client.exchange_token(:code => code) #get an error on this line
#my code to save access token into db goes here.
end

我添加了这张图片

enter image description here

对于我遇到的错误。我认为这可能更有帮助。

最佳答案

我遇到了同样的问题,所以我只是为这一步手动创建了请求。 Soundcloud gem 已经过时了,我敢肯定它与此有关。

    @client = Soundcloud.new(client_id: client_id,
client_secret: client_secret,
redirect_uri:'http://localhost:3000/soundcloud/connected')
@code = params[:code]
response = HTTParty.post("https://api.soundcloud.com/oauth2/token",
body: {
"client_id" => client_id,
"client_secret" => client_secret,
"redirect_uri" => 'http://localhost:3000/soundcloud/connected',
'grant_type'=> 'authorization_code',
"code" => @code
}
)
access_token = response["access_token"]
@authed_client = Soundcloud.new(access_token: access_token)
soundcloud_user = @authed_client.get('/me')
end

希望这对您有所帮助。

关于ruby-on-rails - Ruby on Rails - SoundCloud OAuth 2 未定义方法 `access_token',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38818240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com