Search code examples
ruby-on-railsrubygoogle-api-ruby-client

How to pass my auth_token and refresh tokens to


I'm using the google-api-ruby-client gem in rails.

In the examples I found an example to load GooglePlus data:

client = Google::Apis::PlusV1::PlusService.new
client.key = ENV['GOOGLE_CLIENT_ID']
client.authorization = authorization

I have already obtained both refresh_token and the auth_token with another method (using devise oauth).

How can I generate the authorization object, starting from the tokens I have?


Solution

  • You can create the authorization object by instantiate a new UserRefreshCredentials like this:

     authorization = Google::Auth::UserRefreshCredentials.new(
          client_id: GOOGLE_CLIENT_ID
          client_secret: GOOGLE_CLIENT_SECRET
          scope: GOOGLE_SCOPE,
          access_token: YOUR_AUTH_TOKEN,
          refresh_token: YOUR_REFRESH_TOKEN,
          expires_at: YOUR_EXPIRE_AT_TIMESTAMP,
          grant_type: 'authorization_code')