简体   繁体   English

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

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

I want to view events over specific time range for a specific calendar, but am having trouble using the API, It is a generic API, and it reminds me of using the DOM. 我想查看特定日历在特定时间范围内的事件,但是在使用API​​时遇到了麻烦,这是一个通用API,它使我想起了使用DOM的过程。 The problem is that it seems difficult to work with because much of the information is in generic base classes. 问题在于,由于许多信息属于通用基类,因此似乎很难使用。

How do I get the events for a calendar using Groovy or Java? 如何使用Groovy或Java获取日历的事件? Does anybody have an example of passing credentials using curl? 有没有人使用curl传递凭据的示例?

Example code would be appreciated. 示例代码将不胜感激。

If you do not need to alter the calendar, you only need to get the calendars private feed url, and you can use something like this (taken from the http://eu.gr8conf.org/agenda page). 如果您不需要更改日历,则只需要获取日历的私有提要URL,就可以使用类似的东西(摘自http://eu.gr8conf.org/agenda页面)。 It uses the ICal4J library . 它使用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

Happy hacking. 骇客入侵。

This document has examples for most of the common use cases. 本文档包含大多数常见用例的示例。 For example, here's the code for retrieving events for a specific time range 例如,这是用于在特定时间范围内检索事件的代码

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

You could make this a bit Groovier, using something like: 您可以使用类似以下的方法使它更具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