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.
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
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
}
]
}
}
}
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!
$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);
I am working in Grails and this works for me.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.