Fez
Fez

Reputation: 29

How to do a http get request with Oauth token in ruby on rails

I am recently doing RoR Oauth with a 3rd party API. I am struggling with how I can call the api with the token I already get. The API reference said I should do a GET request. Below are my codes right now:

auth = "Bearer "+hash["access_token"]
uri = URI.parse("https://api.23andme.com/1/user/")
req = Net::HTTP::Get.new(uri.to_s,{'Authorization' => auth})
response = Net::HTTP.start(uri.host,uri.port){|http|
            http.request(req)
}

I was thinking that perhaps the "auth" variable is not correctly set.. The authorization toke is in a format of "Bearer yourToken". I am getting HTTPBadRequest for now. But by doing "curl -H" I can get the json data. Any thoughts?

Upvotes: 0

Views: 2178

Answers (1)

Fez
Fez

Reputation: 29

I figured that out. It was because the GET request was towards a "https" address, so I need to add ".use_ssl = true". Thanks for viewing

Upvotes: 2

Related Questions