Basically, I've been using the PHP Google API Client library for accessing gmail inbox of multiple users(who've allowed access through a oAuth2 workflow) and extracting some data...
Observations: The Client gets authenticated properly only after 10 to 15 mins of time... Once a token is used to authenticate a user's gmail inbox, data is accessible for that user. but when the next token is used to authenticate another user's gmail inbox, the PHP google api client doesn't reload but uses the previous user(I suspect it's been cached / stored in session).
Code flow:
<?php
$tokenArray = array();
foreach($tokenArray as $token) {
$googleclient = getGoogleClient($token);
//$googleclient is stale even after the second iteration of the foreach loop
$service = new Google_Service_Gmail($googleclient);
$googleuser = "me";
//if we change the variable $googleuser to some email address "[email protected]", we get a "Delegation denied for [email protected]"
$userprofile = $service->users->getProfile($googleuser);
var_dump($userprofile);//same data
}
?>
if we take it out of the loop and make separate calls after 25 - 30 mins(or restart the apache webserver), The second token is used in the client library properly.
Is it because the Google API PHP Client Library is caching the object and reusing it for 30 mins or am I missing something?
My question is what should I do to reload the client while handling more than one token?
Is there a proper way / any other way to initialize the client?
Do any of you have any code snippets for PHP Google API Client library... I've checked it in the official docs but to no avail...
Thanks for any help