erebusnz / gapi-google-analytics-php-interface

GA:PI() - Google Analytics PHP Interface
167 stars 86 forks source link

token expire after 1 hour, what code for refresh token ?? #139

Closed urmila-patel closed 8 years ago

urmila-patel commented 8 years ago

please give me solution

erebusnz commented 8 years ago

As the token is fetched in the constructor, it will only do this when GAPI is first started - when you actually do this:

$ga = new gapi("XXXXXXXX@developer.gserviceaccount.com", "key.p12");

Therefore I suggest just simply creating a new object when this happens. Generally PHP scripts are not long running so this isn't a problem.

If you want, you can also add a new method to gapi.class.php (under the getToken function) with the following code:

private function fetchToken($email, $key, $delegate_email  = null) {
  $this->auth_method->fetchToken($client_email, $key_file, $delegate_email);
}

This will give you a method to refresh the token, please let me know if this doesn't work.