【发布时间】:2017-05-15 17:32:37
【问题描述】:
我已经成功地能够使用 PHP 从单个日历中获取 freeBusy 数据,但是当我尝试按照 Google 的建议在一次调用中获取多个日历时:
"items":
[
{
"id": string
}
]
我似乎无法使用 PHP 来使数组对象正确,因为我尝试了 StackOverflow 上的几个示例以及我处理 PHP 数组的一般技能但没有成功。目的是将多个日历 ID 作为一个数组,然后循环遍历该数组以根据 Google API 使请求对象正确。有没有人遇到过同样的问题,并且实际上尝试过使用多个日历 ID。我有一种轻微的感觉,这可能是 Google 日历的 PHP SDK 中的一个错误。任何人都可以指出任何方向吗?这是我的单个日历 ID 的工作代码:
$client = new Google_Client();
$client->setAuthConfig("credentials/oauth-credentials.json");
$client->setScopes('https://www.googleapis.com/auth/calendar');
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->useApplicationDefaultCredentials();
$cal = new Google_Service_Calendar($client);
$calendarId = 'narvik.kommune.no_2d37393134@resource.calendar.google.com';
//$calendarId = array('narvik.kommune.no_37383343730@resource.calendar.google.com','narvik.kommune.no_2d1383134@resource.calendar.google.com');
$freebusy_req = new Google_Service_Calendar_FreeBusyRequest();
$freebusy_req->setTimeMin(date(DateTime::ATOM, strtotime('2017-05-01T08:00:00.000Z')));
$freebusy_req->setTimeMax(date(DateTime::ATOM, strtotime('2017-05-19T17:00:00.000Z')));
$freebusy_req->setTimeZone($timezone);
$freebusy_req->setCalendarExpansionMax(10);
$freebusy_req->setGroupExpansionMax(10);
$item = new Google_Service_Calendar_FreeBusyRequestItem();
$item->setId($calendarId);
$freebusy_req->setItems(array($item));
$query = $cal->freebusy->query($freebusy_req);
$response_calendar = $query->getCalendars();
$busy_obj = $response_calendar[$calendarId]->getBusy();
这是结果 print_r($busy_obj);
Array
(
[0] => Google_Service_Calendar_TimePeriod Object
(
[end] => 2017-05-01T14:50:00Z
[start] => 2017-05-01T09:00:00Z
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
【问题讨论】:
-
也感谢您的帖子!我到处寻找如何使用谷歌新的 PHP 日历库。您在哪里找到如何使用
Google_Service_Calendar_FreeBusyRequest和Google_Service_Calendar_FreeBusyRequestItem?