Reputation: 79
I use this code for getting Google calendars list:
// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("[email protected]", "mypassword");
// Send the request and print the response
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);
System.out.println("Your calendars:");
System.out.println();
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEntry entry = resultFeed.getEntries().get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
This code return me calendars list, but I need to get all events from this calendar about today. How can I do that?
Upvotes: 0
Views: 2550
Reputation: 111
You can also use a this default URL, instead of specifying [email protected],
"https://www.google.com/calendar/feeds/default/private/full"
And I think you should use CalendarEventFeed
Object instead of CalendarFeed
See this code snippet below:
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myService.setUserCredentials(p.getgUser(), p.getgPassword());
DateTime dt = new DateTime();
myQuery.setMinimumStartTime(DateTime.now());
myQuery.setMaximumStartTime(dt);
CalendarEventFeed resultFeed = myService.query(myQuery, CalendarEventFeed.class);
Then traverse the contents of resultFeed
.....
CalendarEventFeed resultFeed = calendarData
for (int i = 0; i<calendarData.getEntries().size(); i++) {
CalendarEventEntry entry = calendarData.getEntries().get(i);
.....
Upvotes: 0
Reputation: 21
If you are using the sample program to start with please use ..../private/full
to get the events from Calendar.
For example:
"https://www.google.com/calendar/feeds/[email protected]/private/full");
Upvotes: 1
Reputation: 39950
Assuming you're using the official GData API:
Try using the getFeed(Query query, …)
overload with a CalendarQuery
- that seems to let you specify the range for the start time of an event.
Upvotes: 0