简体   繁体   English

Google Calendar API V3批处理列表事件

[英]Google Calendar API V3 Batch list events

I've successfully implemented (using the java client library) authentication and retrieval of calendars. 我已经成功实现了(使用Java客户端库)日历的身份验证和检索。 My problem is, I want to retrieve a list of events from multiple calendars, but the time it takes to send an individual API request for each calendar starts to add up, resulting in 20 second page load times if I have a lot of calendars enabled. 我的问题是,我想从多个日历中检索事件列表,但是为每个日历发送一个单独的API请求所花费的时间开始累加,如果启用了很多日历,则导致20秒的页面加载时间。 I understand that the API doesn't provide a way to request events from multiple calendars, but can I use the BatchRequest class to group my requests? 我了解API并未提供从多个日历中请求事件的方法,但是我可以使用BatchRequest类对请求进行分组吗?

I've been able to get this example to work to insert multiple calendars in batch. 我已经能够使本示例能够批量插入多个日历。

https://code.google.com/p/google-api-java-client/source/browse/calendar-cmdline-sample/src/main/java/com/google/api/services/samples/calendar/cmdline/CalendarSample.java?repo=samples https://code.google.com/p/google-api-java-client/source/browse/calendar-cmdline-sample/src/main/java/com/google/api/services/samples/calendar/cmdline/ CalendarSample.java?repo=samples

But I can't extend this to listing events. 但是我不能将其扩展到列出事件。 Essentially, I want to do this: 本质上,我想这样做:

for (int i=0; i < calendarIDs.length; i++) {
    client.events().list(calendarIDs[i]).queue(batch, callback);
}
batch.execute();

I just finally figured it out using a slightly different approach. 我终于使用稍微不同的方法弄清楚了。 Rather than using the queue function for the list object, using the client's batch.queue function: 而不是使用list对象的queue函数,而是使用客户端的batch.queue函数:

BatchRequest batch = client.batch();            
for (int i=0; i< calendarIDs.length; i++) {    
    List req = client.events().list( calendarIDs[i]);        
    batch.queue(req.buildHttpRequest(), Calendar.class, GoogleJsonErrorContainer.class, mycallback);
}           
batch.execute();

This seems to have improved performance a lot. 这似乎改善了很多性能。

I'm doing something that look like what you want, but i'm not using batch, here is an example of my code : 我正在做的事情看起来像您想要的,但是我没有使用批处理,这是我的代码示例:

CalendarEventFeed resultFeed = service.getFeed(calendarUrl, CalendarEventFeed.class); 

for (int i = 0; i < resultFeed.getEntries().size(); i++) { 
     CalendarEventEntry entry = resultFeed.getEntries().get(i); 
} 

So the only thing you will need to change to get event from different calendar is the "calendarUrl", this how you can get your calendar URL 因此,您需要更改以从其他日历获取事件的唯一事情是“ calendarUrl”,这就是获取日历URL的方式

calendarUrl = new URL(calendar.getLink(Link.Rel.ALTERNATE, Link.Type.ATOM).getHref()); 

where "calendar" is a CalendarEntry from google lib. 其中“ calendar”是来自Google lib的CalendarEntry。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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