2010-06-11 54 views
0

我想查看特定日历的特定时间范围内的事件,但无法使用API​​,它是一种通用API,它让我想起使用DOM。问题在于它似乎很难处理,因为大部分信息都在泛型基类中。如何使用Google日历API获取特定时间范围内的所有日历条目

如何使用Groovy或Java获取日历的事件? 有没有人有使用curl传递凭据的例子?

示例代码将不胜感激。

回答

1

This document有大多数常见用例的例子。例如,下面是用于检索事件在特定的时间范围

URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/private/full"); 

CalendarQuery myQuery = new CalendarQuery(feedUrl); 
myQuery.setMinimumStartTime(DateTime.parseDateTime("2006-03-16T00:00:00")); 
myQuery.setMaximumStartTime(DateTime.parseDateTime("2006-03-24T23:59:59")); 

CalendarService myService = new CalendarService("exampleCo-exampleApp-1"); 
myService.setUserCredentials("[email protected]", "mypassword"); 

// Send the request and receive the response: 
CalendarEventFeed resultFeed = myService.query(myQuery, Feed.class); 

你可以做这一点更巧妙,使用类似的代码:

def myQuery = new CalendarQuery("http://www.google.com/calendar/feeds/default/private/full".toURL()).with { 
    minimumStartTime = DateTime.parseDateTime("2006-03-16T00:00:00"); 
    maximumStartTime = DateTime.parseDateTime("2006-03-24T23:59:59"); 
    it 
} 

def myService = new CalendarService("exampleCo-exampleApp-1"); 
myService.setUserCredentials("[email protected]", "mypassword"); 

// Send the request and receive the response: 
def resultFeed = myService.query(myQuery, Feed); 
+0

我会尽快尝试了这一点,但不这只是得到日历。我需要实际的日历条目? – BeWarned 2010-06-14 20:57:21

+0

不,它返回条目,注意返回类型(在Java代码中)是'CalendarEventFeed',即它返回日历事件 – 2010-06-14 21:18:59

1

如果您不需要更改日历,则只需要获取日历专用馈送网址,并且您可以使用类似的内容(摘自http://eu.gr8conf.org/agenda页面)。它使用ICal4J library

def url = "http://www.google.com/calendar/ical/_SOME_URL_/basic.ics".toURL() 
def cal = Calendars.load(url) 

def result = cal.components.sort { it.startDate.date }.collect { 
    def e = new Expando() 
    e.startDate = it.startDate.date 
    e.endDate = it.endDate.date 
    e.title = it.summary.value 
    if (it.location) { 
    e.presentation = Presentation.findByName(it.location.value, [fetch:"join"]) 
    } 

    e.toString = { 
    "$startDate: $title" 
    } 

    return e 
} 

result 

快乐的黑客攻击。

相关问题