Refreshing Tokens with Google API for Google Calendar v3

前端 未结 1 1237
無奈伤痛
無奈伤痛 2021-01-15 10:10

I\'m trying to use Google API (PHP) to perform a daily sync between a system calendar and the user\'s Google Calendars. I want a system user to be able to set up access to t

相关标签:
1条回答
  • 2021-01-15 10:27

    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.

    0 讨论(0)
提交回复
热议问题