簡體   English   中英

Ruby on Rails-SoundCloud OAuth 2未定義方法`access_token'

[英]Ruby on Rails - SoundCloud OAuth 2 undefined method `access_token'

我正在Rails 5上制作一個個人soundcloud應用程序,我在使用OAuth時遇到了一些麻煩。 我能夠重定向到Soundcloud的應用程序並向我的用戶授予權限。 當我嘗試將代碼替換為redirect_uri上的令牌時,出現錯誤。 我已經包含了我的代碼和以下錯誤的圖像。

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

我已添加此圖片

在此處輸入圖片說明

對於我得到的錯誤。 我認為這可能會更有幫助。

我遇到了同樣的問題,因此我只是為此步驟手動創建了請求。 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

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM