0

I wish to access a web services api from within a rails application and display the data from the api. The api uses a permanent access_token and a parameter full_access=true. So the url i wish to access is similar to

http://.......com/lists.json?access_token=d10884g521fc4dc964fd9v06a9121f63&full_access=true

I'm having trouble creating a simple get request which includes the access_token so any advice would be helpful. Can I use a simple get request or do I need to implement oauth2?

If so a sample of a very simple client would be helpful

1 Answer 1

1

You can use the Net::HTTP class:

require 'net/http'

url = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
  http.request(req)
}
puts res.body

Hope this helps!

Sign up to request clarification or add additional context in comments.

2 Comments

That is what I would have used as standard but what I do not understand is where the access_token and parameter fit within that request structure?
You can pass GET parameters like this: url = URI.parse('http://www.example.com/index.html?param1=12&access_token=1204239dz5&bla=abla'). Or maybe the Net::HTTP::Get has a method to add properly parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.