使用 Java 从 Google 日历服务读取 XML 响应

发布于 2024-11-04 07:40:32 字数 1794 浏览 3 评论 0原文

我想使用作为 Google 日历 API 的一部分提供的新查询繁忙时间 API 来检索用户的繁忙时间。结果是一个只读提要,其中包含用户的忙碌时间块,如下所示:

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gCal="http://schemas.google.com/gCal/2005"
 xmlns:gd="http://schemas.google.com/g/2005"
 gd:kind='calendar#freebusy' >
  <id>http://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com</id>
  <updated>2010-03-13T00:00:00.000Z</udpated>
  <link rel='self'
  href='https://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com' />
  <author>
    <name>[email protected]</name>
    <email>[email protected]</email>
  </author>
  <gCal:timeRange>
    <gd:when startTime='2010-03-13T00:00:00Z' endTime='2010-03-14T00:00:00Z'/>
  <gCal:timeRange>
  <gCal:busy>
    <gd:when startTime='2010-03-13T14:00Z' endTime='2010-03-13T14:30Z'/>
  </gCal:busy>
  <gCal:busy>
    <gd:when startTime='2010-03-13T16:00Z' endTime='2010-03-13T16:30Z'/>
  </gCal:busy>
</entry>

基于上述返回提要,我如何使用 Calendar Data API for Java 来获取每个忙碌时间块,以便我可以读取并用它们做一些事情,比如打印到终端?此返回的提要类型是什么,CalendarEventFeed、CalendarFeed...?

CalendarService service = new CalendarService("myapp-v1");          
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());    
URL feedUrl = new URL(METAFEED_URL_BASE+FREEBUSY_FEED_URL_SUFFIX+user.username());
CalendarEventFeed resultFeed = service.getFeed(feedUrl, CalendarEventFeed.class);

I want to retrieve a user's busy times using the new querying busy times API provided as part of the Google calendar API. The result is a read-only feed containing the user's blocks of busy-times that looks like the following:

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gCal="http://schemas.google.com/gCal/2005"
 xmlns:gd="http://schemas.google.com/g/2005"
 gd:kind='calendar#freebusy' >
  <id>http://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com</id>
  <updated>2010-03-13T00:00:00.000Z</udpated>
  <link rel='self'
  href='https://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com' />
  <author>
    <name>[email protected]</name>
    <email>[email protected]</email>
  </author>
  <gCal:timeRange>
    <gd:when startTime='2010-03-13T00:00:00Z' endTime='2010-03-14T00:00:00Z'/>
  <gCal:timeRange>
  <gCal:busy>
    <gd:when startTime='2010-03-13T14:00Z' endTime='2010-03-13T14:30Z'/>
  </gCal:busy>
  <gCal:busy>
    <gd:when startTime='2010-03-13T16:00Z' endTime='2010-03-13T16:30Z'/>
  </gCal:busy>
</entry>

Based on the above return feed, how can I use Calendar Data API for Java to get each block of busy time so that I can read and do something with them like printing to the terminal? What is the type of feed this returns, CalendarEventFeed, CalendarFeed,...?

CalendarService service = new CalendarService("myapp-v1");          
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());    
URL feedUrl = new URL(METAFEED_URL_BASE+FREEBUSY_FEED_URL_SUFFIX+user.username());
CalendarEventFeed resultFeed = service.getFeed(feedUrl, CalendarEventFeed.class);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没企图 2024-11-11 07:40:32

AppEngine 支持(自 1.2.8 起)JAXB XML 到对象数据绑定 API。网络上有许多示例和教程(尽管大多数都关注从 XML 模式自动生成类 - 您不需要这个)。示例:http://www.vogella.de/articles/JAXB/article.html< /a>

或者,您也可以使用Java 日历数据 API,和完全放弃 XML 转换步骤。

AppEngine supports (since 1.2.8) JAXB XML-to-objects data binding API. There are many examples and tutorials on the web (although most focus on automatic class generation from XML schema - you do not need this). An example: http://www.vogella.de/articles/JAXB/article.html

Alternatively you could use Calendar Data API for Java, and forgo the XML conversion step altogether.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文