简体   繁体   中英

How do I use the FreeBusyResponse in Google Calendar java API?

I'm trying to determine if the logged in user is free at a given time. So far I've managed to get a FreeBusyResponse, using this code.

String dIn = "2015-09-10 19:00:00";
String dIne = "2015-09-10 20:00:00";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date d = df.parse(dIn);
DateTime startTime = new DateTime(d, TimeZone.getDefault());

Date de = df.parse(dIne);
DateTime endTime = new DateTime(de, TimeZone.getDefault())

FreeBusyRequest req = new FreeBusyRequest();
req.setTimeMin(startTime);
req.setTimeMax(endTime);
Freebusy.Query fbq = client.freebusy().query(req);

FreeBusyResponse fbresponse = fbq.execute();
System.out.println(fbresponse.toString());

This prints

{"kind":"calendar#freeBusy","timeMax":"2015-09-10T10:00:00.000Z","timeMin":"2015-09-10T09:00:00.000Z"}  

All I want is a boolean yes/no response for if the user is busy.

Am I using FreeBusy in the wrong context? I'm new to using google's APIs and still relatively noobish in Java as well, so apologies if the answer is obvious.

While sending request req.setTimeMin(startTime); req.setTimeMax(endTime); to freebusy.query, if you send items .id--> which is the calendar id from which you want to retreive the free/busy info, then in the response you will get "busy": [ { "start": datetime, "end": datetime } which indicates calendar is busy from starting above date to ending date you get in the response. But you dont get any information in true/ false.

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