0

我想查看特定日历的特定时间范围内的事件,但在使用 API 时遇到问题,它是一个通用 API,它让我想起了使用 DOM。问题是它似乎很难使用,因为大部分信息都在通用基类中。

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

示例代码将不胜感激。

4

2 回答 2

1

如果您不需要更改日历,您只需要获取日历的私有提要 url,您可以使用类似这样的内容(取自http://eu.gr8conf.org/agenda页面)。它使用ICal4J 库

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

快乐的黑客。

于 2010-06-12T18:58:54.273 回答
1

本文档包含大多数常见用例的示例。例如,这是检索特定时间范围内的事件的代码

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("jo@gmail.com", "mypassword");

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

您可以使用以下方法使这有点 Groovier:

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("jo@gmail.com", "mypassword");

// Send the request and receive the response:
def resultFeed = myService.query(myQuery, Feed);
于 2010-06-14T07:47:54.900 回答