sreenivas
sreenivas

Reputation: 395

google oauth refresh token long lived solutions

Google OAuth 2.0 Access Token's have an expiry time. I have integrated the Google Calendar API into my Ruby application however the problem is access token is expiring. How can I make the access token long lived one.

cal.login_with_refresh_token('ksdjkf_sdfkasdhfjhaskjdhfkasdhfkasjdlfasld')

{ "access_token" => "ksdjkf_sdfkasdhfjhaskjdhfkasdhfkasjdlfasld",

"token_type" => "Bearer",

"expires_in" => 2324

}

How to make this a long lived one which means untill unless he revokes access from his Google account user can be able to fetch his Calendar events.

Upvotes: 0

Views: 1168

Answers (1)

Jason Kotchoff
Jason Kotchoff

Reputation: 214

Here's how to create a long-lived OAuth token for the Google API:

  1. visit http://console.developers.google.com
  2. API Manager
  3. Credentials
  4. Create Credentials (OAuth client ID)
  5. Application type: Web Application
  6. Authorised redirect URIs: https://developers.google.com/oauthplayground
    • the resultant client ID / client secret is for your access token
  7. visit: https://developers.google.com/oauthplayground/
  8. Click the settings icon to show the OAuth 2.0 configuration
  9. Tick 'Use your own OAuth credentials'
  10. Enter the OAuth Client ID and OAuth Client secret that you have just created
  11. Check the entry for 'Calendar API v3' in the scopes field and click 'Authorize APIs'
  12. Click 'Allow'
  13. Click 'Exchange authorization code for tokens'
    • now you have a Refresh token and Access token for your client id / secret

Here's an example of using that oauth token with the ruby-api-client gem to talk to the Google Play API using signet. You should be able to modify this example to instead use the calendar API pretty easily:

https://gist.github.com/jkotchoff/e60fdf048ec443272045

Note this was inspired by: https://www.youtube.com/watch?v=hfWe1gPCnzc

Upvotes: 1

Related Questions