Refreshing Tokens with Google API for Google Calendar v3

耗尽温柔 提交于 2019-12-01 11:14:52
KENdi

Well, during your authorization with Google, you will receive a token that will expire in 3600 seconds or one hour and it is normal to be expired. So you need to use refresh token to get a new working token.

Here are the steps that you need:

$token = $client->getAccessToken();
$authObj = json_decode($token);
if(isset($authObj->refresh_token)) {
save_refresh_token($authObj->refresh_token);
}

It is important to save this refresh_token, then you can update it with

$client->refreshToken($your_saved_refresh_token);

And then set your new access token to the session:

$_SESSION['access_token'] = $client->getAccessToken();

For more information, check this SO question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!