2016-08-07 5 views
2

私はRails 5で個人的なサウンドクラウドアプリケーションを作っています。私はOAuthにいくつか問題があります。 Soundcloudのアプリにリダイレクトして、私のユーザーに許可を与えることができます。 redirect_uriでトークンのコードを交換しようとすると、エラーが発生します。私は自分のコードと、私が下にあるエラーのイメージを含めました。Ruby on Rails - SoundCloud OAuth 2未定義のメソッド `access_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

を追加しました。もっと役に立つと思った。

答えて

0

私は同じ問題を抱えていたので、この手順で手動でリクエストを作成しました。 Soundcloudの宝石はかなり日付がついている、私はそれがそれと関係があると確信している。

@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 

これが役に立ちます。

関連する問題