Skip to content

Commit

Permalink
Adding sample code to refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
Maru Ahues Bouza committed Nov 27, 2013
1 parent 57dcc1c commit 3fbd152
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions examples/service-account.php
Expand Up @@ -63,19 +63,18 @@
************************************************/
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
} else {
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/books'),
$key
);
// If we were retrieving on behalf of a specific delegated
// user we should set the subject here.
// $cred->sub = "emailaddress@yourdomain.com";
$client->setAssertionCredentials($cred);
$_SESSION['service_token'] = $client->getAccessToken();
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/books'),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();

/************************************************
We're just going to make the same call as in the
Expand Down

0 comments on commit 3fbd152

Please sign in to comment.