I'm trying to get new access token using the refresh token provided during the first login. I'm using the following code to get the user info ,but not able to get it when access token expires
function getTokenInfo($access_token,$refresh_token){
require_once "google_oauth/src/Google_Client.php";
try{
$_googleClient = new Google_Client();
$_googleClient->setClientId(CONSTANT::ClientID);
$_googleClient->setClientSecret(CONSTANT::ClientSecret);
$_googleClient->setRedirectUri(CONSTANT::RedirectURL);
$_googleClient->setDeveloperKey(CONSTANT::DevelopersKey);
$_googleClient->setScopes( "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile");
$_tokenArray['access_token'] = $access_token;
$_googleClient->setAccessToken(json_encode($_tokenArray));
$refTokenArray['refresh_token'] = $refresh_token;
$_googleClient->refreshToken(json_encode($refTokenArray));
if($_googleClient->isAccessTokenExpired()) {
$NewAccessToken = json_decode($_googleClient->getAccessToken());
$access_token =$NewAccessToken->access_token;
}
}catch(Exception $e){
echo $e->getMessage();
}
$info= json_decode(file_get_contents('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.$access_token));
return $info;
}