Google API Client “refresh token must be passed in or set as part of setAccessToken”

后端 未结 9 1365
Happy的楠姐
Happy的楠姐 2020-12-05 07:55

I am currently facing a very strange problem, indeed I\'ve been following this very same guide (https://developers.google.com/google-apps/calendar/quickstart/php) from Googl

9条回答
  •  天命终不由人
    2020-12-05 08:43

    Google has updated their PHP Quickstart, with an improved method to handle this:

    Snippet below:

    // Exchange authorization code for an access token.
    $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
    $client->setAccessToken($accessToken);
    
    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
    $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
    file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
    }
    

提交回复
热议问题