Google API PHP 클라이언트 - 일정 목록 및 이벤트 검색
-
20-12-2019 - |
문제
Google Calendar API에 대한 문서는 오래된 일정 목록을 얻을 수 없습니다.지금까지 내 코드가 있습니다.
<?php
require_once "includes/partials/_header.php";
set_include_path(get_include_path() . '/google-api-php-client/src');
$client_id = 'xxxx.apps.googleusercontent.com';
$service_account = 'xxxx@developer.gserviceaccount.com';
$p12 = 'xxxx-privatekey.p12';
session_start();
require_once 'Google/Client.php';
require_once 'Google/Service/Calendar.php';
$client = new Google_Client();
$client->setApplicationName("Calendrier");
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents($p12);
$client->setClientId($client_id);
$cred = new Google_Auth_AssertionCredentials(
$service_account,
array('https://www.googleapis.com/auth/calendar'),
$key);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
$cal = new Google_Service_Calendar($client);
$events = $cal->calendarList->listCalendarList();
echo "<pre>";
print_r($events);
echo"</pre>";
while(true) {
foreach ($events->getItems() as $event) {
echo $event->getSummary();
print_r($event);
}
$pageToken = $events->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$events = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
?>
.
문서가 오래 되었기 때문에 다른 사이트 에서이 코드를 많이 얻었습니다.모든 통찰력
지금까지 얻는 것은 "항목"이없는 응답입니다
Google_Service_Calendar_CalendarList Object
(
[etag] => "xxxxxxxxxxxx"
[itemsType:protected] => Google_Service_Calendar_CalendarListEntry
[itemsDataType:protected] => array
[kind] => calendar#calendarList
[nextPageToken] =>
[nextSyncToken] => 00001401741798955000
[collection_key:protected] => items
[modelData:protected] => Array
(
[items] => Array
(
)
)
[processed:protected] => Array
(
)
)
. 해결책
allright, 이것은 내가 이것에 소비 한 모든 시간 이후에 퇴비적입니다.어떤 이유로 나는 결코 캘린더를 공개하지 않았다.방금 프로젝트 계정에서 일정에 액세스 할 수있는 모든 권한 부여 단계에서추측하지 않아.
쉬운 수정 ... 캘린더를 해당 설정으로 대중으로 만드십시오.
이벤트의 경우 $ CAL-> 캘린더리스트 파트를
로 대체합니다.$cal->events->listEvents('calendarID', $optionalParams);
.
참고 : 세션의 모든 권한 / 액세스 토큰 항목이 필요할 때도 Google CAL의 문서 페이지가 이전 PHP 클라이언트를 사용하는 것 같습니다.나는 그것이 서비스 계정 (setAssertionCredentials) 만 사용하여 작동해야한다고 믿습니다. 세션 im은 확실하지 않습니다.
제휴하지 않습니다 StackOverflow