Php 撤销令牌OAuth 2谷歌api
我想撤销令牌以延长其使用时间,我的代码以standart redirect->getToken flow开头:Php 撤销令牌OAuth 2谷歌api,php,oauth,oauth-2.0,google-oauth,Php,Oauth,Oauth 2.0,Google Oauth,我想撤销令牌以延长其使用时间,我的代码以standart redirect->getToken flow开头: $code = (array_key_exists('code', $_GET) ? $_GET['code'] : ''); $access_token = json_decode(DB::getToken(), true); $guzzleClient = new \GuzzleHttp\Client(array( 'curl' =
$code = (array_key_exists('code', $_GET) ? $_GET['code'] : '');
$access_token = json_decode(DB::getToken(), true);
$guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false, ), ));
$this->client = new Google_Client();
$this->client->setHttpClient($guzzleClient);
$this->client->setAuthConfig('client_secret.json');
$this->client->addScope("https://www.googleapis.com/auth/calendar");
$this->client->setAccessType('offline');
$this->client->setApprovalPrompt('force');
$this->client->setAccessToken($access_token);
if(!$code && !$access_token) {
$auth_url = $this->client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
}
if($code && !$access_token) {
$this->client->fetchAccessTokenWithAuthCode($code);
$access_token = $this->client->getAccessToken();
DB::saveToken($access_token);
}
在这里,我检查访问令牌是否过期,如果是,我将撤销令牌,并希望继续使用它而不会出现问题:
if($this->client->isAccessTokenExpired()) {
$revoked = $this->client->revokeToken($access_token);
if($revoked) {
$access_token = $this->client->getAccessToken();
}
}
尽管出现了问题和错误,但我得到的令牌已过期或已撤销
错误消息
我做错了什么
我希望撤销后,令牌将再次有效
我希望撤销后,令牌将再次有效
过期或吊销的访问令牌无法再使用。撤销过期的访问令牌也是无用的
我在您的代码中看到您请求脱机
访问令牌。您应该会收到一个刷新令牌。
您需要做的是使用该刷新令牌来获取新的访问令牌。
看。你救了我一天。非常感谢。