내 사용자가 내 Google 캘린더 중 하나를 사용하여 캘린더 일정을 예약/일정을 조정할 수있는 PHP 앱이 있으므로 사용자가 Google 인증을받을 필요가 없습니다. 토큰을 가져 와서 새로 고침 토큰을 저장했지만 지금은 토큰이 만료되었다는 오류 메시지가 표시됩니다. 오류가 발생 출력 액세스 토큰 = { "긴 ... 토큰 ... 문자열", "token_type": "베어러", "expires_in"3600 "access_token은"} 발견 클라이언트를 생성새로 고침 토큰을 사용하는 Google 캘린더 API
인 : (0) OAuth 2.0 액세스 토큰이 만료되었으며 새로 고침 토큰을 사용할 수 없습니다. 자동 승인 된 응답에는 새로 고침 토큰이 반환되지 않습니다.
이 오류가 발생하는 이유를 잘 모릅니다.
function getAccessToken(){
$tokenURL = 'https://accounts.google.com/o/oauth2/token';
$postData = array(
'client_secret'=>'My-Secret',
'grant_type'=>'refresh_token',
'approval_promt'=> 'force',
'refresh_token'=>'My-Refresh-Token',
'client_id'=>'My-Client-ID'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tokenURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tokenReturn = curl_exec($ch);
return $tokenReturn;
}
function outputCalendarByDateRange($client, $startDate='2007-05-01', $endDate='2007-08-01'){
date_default_timezone_set("America/Chicago");
$client->addScope('https://www.googleapis.com/auth/calendar');
try {
$service = new Google_Service_Calendar($client);
}catch(Google_ServiceException $e){
print "Error code :" . $e->getCode() . "\n";
print "Error message: " . $e->getMessage() . "\n";
} catch (Google_Exception $e) {
print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "\n";
}
$optParams = array(
'orderBy'=>'starttime',
'singleEvents'=>False,
'timeMax'=>$endDate,
'timeMin'=>$startDate,
'timeZone'=>'America/Chicago',
'maxResults'=>1000
);
try{
$events = $service->events->listEvents('primary',$optParams);
} catch (Google_ServiceException $e) {
print "Error code :" . $e->getCode() . "\n";
print "Error message: " . $e->getMessage() . "\n";
} catch (Google_Exception $e) {
print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "\n";
}
foreach ($events->getItems() as $event) {
echo $event->getSummary();
}
}
echo "creating a client<br>";
$client = new Google_Client();
$accessToken = getAccessToken();
echo "found access token = ".$accessToken."<br>";
try{
$client->setAccessToken($accessToken);
}
catch (Google_ServiceException $e) {
print "Error code :" . $e->getCode() . "\n";
print "Error message: " . $e->getMessage() . "\n";
} catch (Google_Exception $e) {
print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "\n";
}
outputCalendarByDateRange($client, $today, $tomorrow);
튜토리얼 Google Calendar API with PHP – Service Account에서 빼낸. 여기에서 https://developers.google.com/accounts/docs/OAuth2WebServer 키워드 access_type –