我想使用google api v3 freebusy(php)查找我的三个日历的免费freebusy信息,但我找不到我的代码的正确结尾。我想访问$ freebusy-response的“日历 - 忙碌”值。
由于api-reference上没有示例代码,我无法在网上找到任何正常工作的代码(但很多人要求它)你们是我最后的希望让它运行起来。
...
$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-reference关于响应的内容:
{
"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
}
]
}
}
}
答案 0 :(得分:2)
这是我的解决方案(只有你的代码的setItems部分是错误的):
$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);
希望这有帮助,欢呼!
答案 1 :(得分:0)
$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( array("id"=>"my_calendar_id1@developer.gserviceaccount.com"), array("id"=>"my_calendar_id2@group.calendar.google.com"), array("id"=>"my_calendar_id3@group.calendar.google.com"));
$freebusy->setItems($mycalendars);
$createdReq = $service->freebusy->query($freebusy);
答案 2 :(得分:-2)
我在Grails工作,这对我有用。
def heute = new DateTime(false, new Date().time, null)
def heutePlusEinJahr = new DateTime(false, (new Date() + 365).time, null)
println heute
println heutePlusEinJahr
Events feed = servicecalendar.events().list(calendarId).setTimeMin(heute).setTimeMax(heutePlusEinJahr).execute();
return feed