我們通過3腳Oauth2實現將我們的Ruby on Rails 4應用程序與Infusionsoft的XML-RPC API集成在一起。如何使用紅寶石從Infusionsoft的Oauth獲取訪問令牌?
(文檔在這裏 - https://developer.infusionsoft.com/docs/xml-rpc/#authentication-request-permission)
我們建立了一個重定向操作給用戶發送到與我們的應用程序的ID的Infusionsoft應用認證頁面。
def connect_inf
redirect_to "https://signin.infusionsoft.com/app/oauth/authorize?client_id=XXXXXXX&redirect_uri=https://testappurl.herokuapp.com/websites/1/connect_inf/callback/&response_type=code&scope=full"
end
然後,用戶進行身份驗證之後,用戶被髮送回我們的尋找這樣的URL回調動作......
我們得到的代碼,並使用RESTClient實現到將其發送回Infusionsoft以請求訪問令牌,並按照它們在文檔中指定的順序使用參數。
def get_inf
response = RestClient.post 'https://api.infusionsoft.com/token', :client_id => 'XXXXXXXXXXXXXX', :client_secret => 'XXXXXXX', :code => params[:code], :grant_type => 'authorization_code', :redirect_uri => 'https://testappurl.herokuapp.com/websites/1/connect_inf/callback/', :accept => 'text/xml'
end
這將返回RestClient::BadRequest: 400 Bad Request
我想這已經是與參數是如何被傳遞。
錯誤的請求通常意味着參數錯誤。 「params」的內容是什麼? API真的處理XML嗎? –