title: How to get offline-access with Google APIs
body: <p>I'm trying to get <code>offline access</code> with Google APIs. I have to pull data from Google Calendar without having the user sign-in everytime.</p>
  
  <p>I've added this to my Gemfile:</p>
  
  <p><code>gem 'google-api-client', '~&gt; 0.9'</code></p>
  
  <p>... And added this to my controller:</p>
  
  <pre><code>require 'google/api_client/client_secrets'
  class Api::V1::CalendarAccountsController &lt; Api::V1::BaseController
  ...
  </code></pre>
  
  <p>And in my action:</p>
  
  <pre><code>client_secrets = Google::APIClient::ClientSecrets.load(
    File.join(
      Rails.root,
      'config',
      'client_secrets.json')
    )
  
  @auth_client = client_secrets.to_authorization
  
  @auth_client.update!(
      :scope =&gt; 'https://www.googleapis.com/auth/calendar.readonly',
      :redirect_uri =&gt; '/{callback URL}',
  
      :additional_parameters =&gt; {
        "access_type" =&gt; "offline",
        "include_granted_scopes" =&gt; "true"
      }
  )
  redirect_to @auth_client.authorization_uri.to_s
  </code></pre>
  
  <p>The problem is -- even though I'm specifying <strong>"access_type"</strong> as <strong>"offline"</strong>, I <em>still</em> don't get asked for offline-access privileges in the Google privileges list (I'm attaching a screenie below).</p>
  
  <p>And here's the page Google loads (no offline-access):
  <a href="https://i.stack.imgur.com/SdGNx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SdGNx.png" alt="Google privileges list with no offline-access request"></a></p>
  
  <p>And here's the URL that got generated when I called <code>@auth_client.authorization_uri.to_s</code></p>
  
  <p><a href="https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;client_id=[ID]&amp;redirect_uri=[callback]&amp;response_type=code&amp;scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&amp;from_login=1&amp;as=-23788065e9c098d9&amp;pli=1&amp;authuser=0" rel="nofollow noreferrer">https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;client_id=[ID]&amp;redirect_uri=[callback]&amp;response_type=code&amp;scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&amp;from_login=1&amp;as=-23788065e9c098d9&amp;pli=1&amp;authuser=0</a></p>
  
  <p>Am I missing something?</p>