1

Following is what I am trying to do -

client = Google::APIClient.new
client.authorization.client_id = 'XXXX'
client.authorization.client_secret = 'XXXXX'
client.authorization.scope = 'https://www.googleapis.com/auth/calendar'
client.authorization.redirect_uri = 'http://www.aaaaa.com/'
calendar = client.discovered_api('calendar', 'v3')

In order to get access_token to make further requests, i make a call to client.authorization.fetch_access_token!

Response I get is :

Signet::AuthorizationError: Authorization failed.  Server message:
{
  "error" : "invalid_request"
}
from D:/main/tools/jruby/lib/ruby/gems/1.8/gems/signet-0.4.4/lib/signet/oauth_2/client.rb:865:in `fetch_access_token'

Later I changed made a few changes and set the grant_type to password and supplied user name and password.

client.authorization.grant_type = 'password'
client.authorization.username = 'aaaaa'
client.authorization.password = 'aaaaa'

Still facing the same issue.

Documentation is not of much help. Is there any setting that I am missing?

RSK
  • 17,210
  • 13
  • 54
  • 74
  • invalid_request (which means there's a 400 there under the covers) usually means the request is somehow malformed. Assuming your client is registered, your code looks sane. Any more debugging output available? – Tim Bray Mar 08 '13 at 19:58

1 Answers1

0

You probably already figured this out, but I think I know what the problem is. You must first navigate (in a browser) to client.authorization.authorization_uri, which is where you will be asked to grant access to the Google account. After that, you will be redirected to client.authorization.redirect_uri, which is http://www.aaaaa.com/ in the code you provided. There will be an authorization code appended on to the URL: http://www.aaaaa.com?code=<code here>. You must set client.authorization.code equal to that authorization code. Once you have done that, you should be able to call client.authorization.fetch_access_token! and then make calls to the API.

thevoiceless
  • 93
  • 3
  • 4