php - Google Calendar API unable to referesh token -


please check code snippet:

$client = new google_client(); $client->setapplicationname(application_name); $client->setscopes(scopes); $client->setauthconfig(client_secret_path); $client->setaccesstype('offline'); $client->sethttpclient(new guzzlehttp\client(['verify' => false])); $client->setredirecturi(redirecturi); $client->setapprovalprompt('force'); $client->setaccesstoken($accesstoken);  try {     #if($client->isaccesstokenexpired()){         $accesstoken['refresh_token'] = $_session["ac"][$email]["refresh_token"];         $client->fetchaccesstokenwithrefreshtoken($accesstoken);          $_session["ac"][$email]['token'] = $client->getaccesstoken();         $_session["ac"][$email]['refresh_token'] = $client->getrefreshtoken();     #} } catch (exception $e) {     return $e->getmessage(); }   $service = new google_service_calendar($client); $calendarid = 'primary'; $optparams = array(   'maxresults' => $limit,   'orderby' => 'starttime',   'singleevents' => true,   'timemin' => date('c'), ); $results = $service->events->listevents($calendarid, $optparams);  $events = []; foreach ($results->getitems() $event) {     $events[] = [         'start' => $event->start->datetime,         'summary' => $event->getsummary(),         'htmllink' => $event->htmllink,         'email' => $event->creator->email,         'description' => $event->description,         'location' => $event->location,         'name' => $event->creator->displayname,         'end' => $event->end->datetime,     ]; } return $events; 

i saving token this

$accesstoken = $client->fetchaccesstokenwithauthcode($authcode); $client->setaccesstoken($accesstoken);  $refreshtoken = $client->getrefreshtoken();  $oauth = new google_service_oauth2($client); $email = (string)$oauth->userinfo->get()->email;  $_session["ac"][$email]['token'] = $accesstoken;   $_session["ac"][$email]['refresh_token'] = $refreshtoken;   

this work fine 1 hour, able events in 1 hour, after 1 hour token expired , unable next token.

can please me?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -