title: How to refresh token with Google API client?
body: <p>I've been playing around with the Google Analytics API (V3) and have run into som errors. Firstly, everything is set up correct and worked with my testing account. But when I want to grab data from another profile ID (Same Google Accont/GA Account) I get an 403 Error. The strange thing is that data from some GA accounts will return data whilst other generate this error.</p>
  
  <p>I've revoked the token and authenticated one more time, and now it seems like I can grab data from all of my accounts. Problem solved? Not. As the access key will expire, I will run into the same issue again.</p>
  
  <p>If I have understood things right, one could use the resfreshToken to get a new authenticationTooken.</p>
  
  <p>The problem is, when I run: </p>
  
  <pre><code>$client-&gt;refreshToken(refresh_token_key) 
  </code></pre>
  
  <p>the following error is returned:</p>
  
  <pre><code>Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'
  </code></pre>
  
  <p>I’ve checked the code behind the refreshToken method and tracked the request back to the “apiOAuth2.php” file. All parameters are sent correctly. The grant_type is hard coded to ‘refresh_token’ within the method, so it’s hard for me to understand what’s wrong. The parameter array looks like this:</p>
  
  <pre><code>Array ( [client_id] =&gt; *******-uqgau8uo1l96bd09eurdub26c9ftr2io.apps.googleusercontent.com [client_secret] =&gt; ******** [refresh_token] =&gt; 1\/lov250YQTMCC9LRQbE6yMv-FiX_Offo79UXimV8kvwY [grant_type] =&gt; refresh_token )
  </code></pre>
  
  <p>The procedure is as follows.</p>
  
  <pre><code>$client = new apiClient();
  $client-&gt;setClientId($config['oauth2_client_id']);
  $client-&gt;setClientSecret($config['oauth2_client_secret']);
  $client-&gt;setRedirectUri($config['oauth2_redirect_uri']);
  $client-&gt;setScopes('https://www.googleapis.com/auth/analytics.readonly');
  $client-&gt;setState('offline');
  
  $client-&gt;setAccessToken($config['token']); // The access JSON object.
  
  $client-&gt;refreshToken($config['refreshToken']); // Will return error here
  </code></pre>
  
  <p>Is this a bug, or have I completely misunderstood something?</p>