繁体   English   中英

如何使用Google Calendar API获取特定时间范围内的所有日历条目

[英]How do I get all the calendar entries for a particular time range using Google Calendar API

我想查看特定日历在特定时间范围内的事件,但是在使用API​​时遇到了麻烦,这是一个通用API,它使我想起了使用DOM的过程。 问题在于,由于许多信息属于通用基类,因此似乎很难使用。

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

示例代码将不胜感激。

如果您不需要更改日历,则只需要获取日历的私有提要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

骇客入侵。

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

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);

暂无
暂无

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

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