在Google Calendar API中回到Get Refreshtoken的问题



我从Google oauth2.0日历API中获取刷新访问令牌的问题。我的代码是:

function getClient() {
  $client = new Google_Client();
  $client->setApplicationName(APPLICATION_NAME);
  $client->setScopes(SCOPES);
  $client->setAuthConfig(CLIENT_SECRET_PATH);
  $client->setAccessType('offline');
$client->setApprovalPrompt('force');
 $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
  // Load previously authorized credentials from a file.
  if (file_exists($credentialsPath)) {
    $accessToken = json_decode(file_get_contents($credentialsPath), true);
    $client->setAccessToken($accessToken);
      // Refresh the token if it's expired.
      if ($client->isAccessTokenExpired()) {
                try {
        $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
                }
                catch(Exception $e) { die("Error is: ".$e->getMessage()); }  
        file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
      }
    $authUrl = '';
    return $client;
  }
}

我在fetchAccessTokenWithRefreshToken中得到例外。我在哪里尝试捕获。获得异常Error is: refresh token must be passed in or set as part of setAccessToken。根据GitHub上的线程,我还使用客户端对象传递了$client->setAuthConfig(CLIENT_SECRET_PATH); $client->setAccessType('offline');。请帮助解决此错误。

$ client-> fetchaccesstokenwithrefreshtoken($ client-> getRefreshtoken(((;

$ client-> getRefreshtoken((应在$ client-> fetchaccesstokenwithrefreshtoken((

使用之前存储在var/对象中
$refresh_token = $client->getRefreshToken(); 
$client->fetchAccessTokenWithRefreshToken($refresh_token);

最新更新