简体   繁体   中英

How do I use freebusy info in Google Calendar API (php)?

I'm using the Google Client API PHP Library.

I have found this answer to a similar question and it seems to do something and return some info.... but I don't know how the heck to use it :/

Here's the part of my code

$freebusy_req = new Google_FreeBusyRequest();
$freebusy_req->setTimeMin('2014-02-21T02:30:00Z');
$freebusy_req->setTimeMax('2014-02-21T17:00:00Z');
$freebusy_req->setTimeZone('America/Phoenix');
$item = new Google_FreeBusyRequestItem();
$item->setId(CALENDAR_ID);
$freebusy_req->setItems(array($item));
$query = $cal->freebusy->query($freebusy_req);

If I dump the variable and check it out, it seems to be returning some data but I don't know how to use it. I can't find any documentation on the subject either.

I just want to see if a specific calendar is busy at a specified time. And get some sort of 'true/false' out of it. Thanks.

You can try echo json_encode($query) to see the response more easily. It will show busy time interval between the time you specified.

If you want to get a true/false out of it you can check if there's anything in between the [ ] at 'busy' in the output you get from the api. Following Colleen's answer, this is what got me where I wanted to be.

if (json_encode($query['calendars'][CALENDAR_ID]['busy']) === '[]') 
   {
     $busy = false; //nothing between [ and ], calendar is free
   }

else 
   {
     $busy = true; //calendar is busy
   }

(Please be aware I'm new to php and json, so this may very well be a quick and dirty solution.)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM