Ruby on Rails Friday, May 25, 2012

Hi all

I'm getting a 'Connection reset by peer' while getting an access token during oAuth from a third party API. Here's the code snippet:

def accesstoken
@code = params[:code]

url = URI.parse('access token request url')
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'auth_code' => @code, 'client_id'=>'my_client_id', 'client_secret'=>'my_secret_key'}, ';')
res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
# res.error!
end

render :text => @code.inspect

end

I get a valid authorization code but unable to proceed to get access token due to above error. The third party API has to return a response in json format.
Any help is much awaited and appreciated!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/gQolUkV75zAJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment