问题描述
我想使用 google api v3 freebusy (php) 来查找我的三个日历的免费空闲忙信息,但是我没有找到我的代码的正确结尾.我想访问 $freebusy-response 的日历 - 忙碌"值.
I want to use the google api v3 freebusy (php) to find free freebusy-information of three of my calendars, but I dont find the correct ending to my code. I want to access the "calendars - busy" values of the $freebusy-response.
由于 api-reference 中没有示例代码,而且我在网络上找不到任何可用的代码(但很多人要求它),你们是我运行它的最后希望.
Since there is no example-code at the api-reference and i couldnt find any working code on the web (but lots of people asking for it) you guys are my last hope to get this running.
...
$service = new Google_CalendarService($client); // successfully connected
$freebusy = new Google_FreeBusyRequest();
$freebusy->setTimeMin('2013-07-08T08:00:00.000-07:00');
$freebusy->setTimeMax('2013-07-08T10:00:00.000-07:00');
$freebusy->setTimeZone('Europe/Berlin');
$freebusy->setGroupExpansionMax(10);
$freebusy->setCalendarExpansionMax(10);
$mycalendars= array("my_calendar_id1@developer.gserviceaccount.com","my_calendar_id2@group.calendar.google.com","my_calendar_id3@group.calendar.google.com");
$freebusy->setItems = $mycalendars;
$createdReq = $service->freebusy->query($freebusy);
echo $createdReq->getKind(); // works
echo $createdReq->getTimeMin(); // works
echo $createdReq->getTimeMax(); // works
$s = $createdReq->getCalendars($diekalender);
Print_r($s, true); // doesn't show anything
// needed: the value of "calendars": { (key): { "busy" - array of one or all calendars
这是 API 参考关于响应的说明:
This is what the API-reference says about the response:
{
"kind": "calendar#freeBusy",
"timeMin": datetime,
"timeMax": datetime,
"groups": {
(key): {
"errors": [
{
"domain": string,
"reason": string
}
],
"calendars": [
string
]
}
},
"calendars": {
(key): {
"errors": [
{
"domain": string,
"reason": string
}
],
"busy": [
{
"start": datetime,
"end": datetime
}
]
}
}
}
推荐答案
这是我的解决方案(只有你代码的 setItems 部分是错误的):
Here's my resolution (only the setItems part of your code is wrong):
$freebusy_req = new Google_FreeBusyRequest();
$freebusy_req->setTimeMin(date(DateTime::ATOM, strtotime($date_from)));
$freebusy_req->setTimeMax(date(DateTime::ATOM, strtotime($date_to)));
$freebusy_req->setTimeZone('America/Chicago');
$item = new Google_FreeBusyRequestItem();
$item->setId('{calendarId}');
$freebusy_req->setItems(array($item));
$query = $service->freebusy->query($freebusy_req);
希望这会有所帮助,加油!
Hope this helps, cheers!
这篇关于如何完成此 Google Calendar Api v3 - FreeBusy PHP - 示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!