내 액세스 토큰이 만료되었는지 어떻게 알 수 있습니까?Google Api에서 액세스 토큰이 만료되는지 확인하는 방법 PHP
내가 곱슬 곱슬 사용하려면
"새 토큰 가져 오기"를 인쇄합니다 나는 시도 및 캐치
try {
$result = file_get_contents('https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token='.$accesstoken);
print_r($result);
}
catch(Exception $e){
echo "Get new token";
}
를 사용하고 있지만, 여전히 다음 file_get_contents에서 오류를 가져옵니다
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token='.$accesstoken);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
그러면 여기서 오류를 잡으려면 어떻게해야합니까?
//if error because access token is invalid,
do here
// my fixed solution
$response= json_decode($result);
if($response->error){ // if result has errors
echo "Get new token";
}
당신의 질문은 무엇입니까? 새로운 액세스 토큰을 요청할시기 또는 새로운 액세스 토큰을 묻는 방법을 알고 싶습니까? – Shadow
@shadow 예, 내 액세스 토큰이 만료되었는지 알고 싶습니다. 내 솔루션을 사용하여 내 게시물을 편집했습니다. 언제든지 의견을 말하십시오. –