我试图检索谷歌日历的事件。到目前为止,我可以连接到日历,但我得到一个空数组,而不是我的测试日历中存在的两个事件。
以下是我使用的代码:
// Service Account info
$client_id = '###';
$service_account_name = '###';
$key_file_location = OW::getPluginManager()->getPlugin('event')->getStaticUrl() . 'Oxwall-GoogleCal-eae5f581a202.p12';
// Calendar id
$calName = 'n496ktfo3mj4i669keujfq9j70@group.calendar.google.com';
$client = new Google_Client();
$client->setApplicationName("Calendar test");
$service = new Google_Service_Calendar($client);
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Calendar::CALENDAR, Google_Service_Calendar::CALENDAR_READONLY),
$key
);
$client->setAssertionCredentials($cred);
$cals = $service->calendarList->listCalendarList();
echo '<pre>';
print_r($cals);
echo '</pre>';
// Convert recurring events to single events
// Look for events in the next week - now to now+1week
$params = array(
'singleEvents' => TRUE,
'timeMin' => (new DateTime())->format(DateTime::RFC3339),
'timeMax' => (new DateTime())->add(new DateInterval('P1W'))->format(DateTime::RFC3339),
);
$events = $service->events->listEvents($calName, $params);
echo '<pre>';
print_r($events);
echo '</pre>';
foreach ($events->getItems() as $event) {
echo "Summary: ", $event->getSummary(), "\n";
echo "Location: ", $event->getLocation(), "\n";
echo "Start: ", $this->fmt_gdate($event->getStart()), "\n";
echo "End: ", $this->fmt_gdate($event->getEnd()), "\n";
}
结果我得到了:
Google_Service_Calendar_CalendarList Object(
[collection_key:protected] => items
[internal_gapi_mappings:protected] => Array
(
)
[etag] => "1424704655166000"
[itemsType:protected] => Google_Service_Calendar_CalendarListEntry
[itemsDataType:protected] => array
[kind] => calendar#calendarList
[nextPageToken] =>
[nextSyncToken] => 00001424704655166000
[modelData:protected] => Array
(
[items] => Array
(
)
)
[processed:protected] => Array
(
)
) Google_Service_Calendar_Events对象 ([collection_key:protected] =&gt;项目 [internal_gapi_mappings:protected] =&gt;排列 ( )
[accessRole] => reader
[defaultRemindersType:protected] => Google_Service_Calendar_EventReminder
[defaultRemindersDataType:protected] => array
[description] => This is for testing only.
[etag] => "1424706436571000"
[itemsType:protected] => Google_Service_Calendar_Event
[itemsDataType:protected] => array
[kind] => calendar#events
[nextPageToken] =>
[nextSyncToken] => CPi-voi1-MMCEPi-voi1-MMCGAE=
[summary] => Agenda Test
[timeZone] => Asia/Calcutta
[updated] => 2015-02-23T15:47:16.571Z
[modelData:protected] => Array
(
[defaultReminders] => Array
(
)
[items] => Array
(
)
)
[processed:protected] => Array
(
))
你能告诉我我做错了吗?