In the past for days I wasted of my good much time now I managed to get refresh token.. I couldn't get a refresh token before..
My purpose is to synchronize Google calendar data without Google login of users
What I did to do so:
- I stored token information in my database
- when user wants to synchronize I used the stored information to pull data from Google calendar API but then the token has expiration date, which is an hour
- I assume I can get an usable token using refresh token and pull data from Google calendar api again ( but how ? )
extra question : can I get another refresh token from the previous refresh token? Is it like I can get a refresh token over and over again?
Here's some my code:
public function __construct()
{
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope(Google_Service_Calendar::CALENDAR); // CALENDAR READONLY 는 읽기만 가능
$guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
$client->setHttpClient($guzzleClient);
$client->setAccessType ("offline");
$client->setApprovalPrompt ("force");
$client->setRedirectUri('http://localhost/smart_mirror/GoogleCalendarApi-master/public/api/cal');
$this->client = $client;
}
$refresh_token=$this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
$this->client->getAuth()->refreshToken($this->client->getAuth()->getRefreshToken());
$refresh_token=$this->client->getAccessToken();