How to refresh access_token for the Google API with Ruby client?
<p>I have a working app (Rails) that authenticates a user and saves her tokens in a Redis store. </p>

<p>If I've understood it correctly, using googleauth together with google-api-client, the client object will refresh the access token (by itself) as needed? This doesn't happen though, the token expires and some time after that I get a 403 error. </p>

<p>If the problem is on my side - can/should I invoke a new access_token manually, and if so how do I do that? </p>

<p>The code I've used is mainly taken from the <a href="https://developers.google.com/google-apps/calendar/quickstart/ruby" rel="nofollow">quickstart guide</a>. </p>

<pre><code>gem 'google-api-client', require: 'google/apis/calendar_v3'

def authorizer
  scope = Google::Apis::CalendarV3::AUTH_CALENDAR
  client_id = Google::Auth::ClientId.from_hash(JSON.parse(ENV['GOOGLE_CLIENT_SECRETS']))
  token_store = Google::Auth::Stores::RedisTokenStore.new(redis: $redis)
  authorizer = Google::Auth::WebUserAuthorizer.new(client_id, scope, token_store)
  authorizer
end

def authenticate_the_user
  user_id = "1"
  credentials = authorizer.get_credentials(user_id)
  redirect_to authorizer.get_authorization_url(login_hint: user_id, request: request, base_url: "http://localhost:3000")
end

def handle_callback
  credentials = authorizer.get_and_store_credentials_from_code(user_id: "1", code: params[:code], base_url: "http://localhost:3000/oauth2callback")
end
</code></pre>