0

I'm writing a small cli tool, that should check my calendar and do some stuff according to my appointments.
I'm struggling a little bit with the OAuth2 authentication. I've checked the scope and the client_id with the curl tool like this:

curl -d "client_id=12345...&scope=scope=https://www.googleapis.com/auth/calendar.readonly" https://accounts.google.com/o/oauth2/device/code

This way, I get the right response.

{
 "device_code" : "somestuff",
 "user_code" : "otherstuff",
 "verification_url" : "http://www.google.com/device",
 "expires_in" : 1800,
 "interval" : 5
}

But, when I try to use Net::HTTP in Ruby I just get HTTP state 200. I've done it this way:

res = Net::HTTP.post_form(uri, {'client_id' =>'1234....apps.googleusercontent.com', 'scope' => 'https://www.googleapis.com/auth/calendar.readonly' })

If I check the res variable afterwards I get the state 302, but I guess this is correct.
Can someone tell me what I'm, doing wrong so I don't get the JSON response? Should I try something different than Net::HTTP?

Shimu
  • 1,137
  • 11
  • 25

1 Answers1

0

res is a variable containing all the response data, not just the text of the response. If you puts res.body after your post_form() call, you should find your JSON (which you can parse with the JSON module).

Alex P
  • 5,942
  • 2
  • 23
  • 30
  • Thanks for the hint. I've tried this, but it says, that the variable is empty (nil). After I tried to access res.body it worked. Thanks – Shimu Jun 15 '14 at 09:57