谷歌日历java api

时间:2009-12-18 14:34:28

标签: java google-api google-calendar-api

我有CalendarEntry的对象

我知道 http://www.google.com/calendar/feeds/example@gmail.com/allcalendars/full 是所有日历的Feed网址

但我如何从CalendarEntry实例获取此Feed网址?

因为我想在指定的日历中发布一个新条目,我需要这个网址。

谢谢!

2 个答案:

答案 0 :(得分:1)

我建议您在代码中指定该网址,如下面的代码段:

CalendarService myService = new CalendarService("CalendarService");
myService.setUserCredentials("example@gmail.com", "yourPassword");
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);
System.out.println("Your calendars:");
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
  CalendarEntry entry = resultFeed.getEntries().get(i);
  System.out.println("\t" + entry.getTitle().getPlainText());
}

CalendarEntry实例将存储由指定网址检索的每个日历(主日历,辅助日历,导入日历)。

答案 1 :(得分:0)

如果我理解你的问题,你想这样做:

public static URL toCalendarFeedURL(CalendarEntry calendarEntry) {
    try {
        String cal = "https://www.google.com/calendar/feeds" + calendarEntry.getEditLink().getHref().substring(63) + "/private/full";
        return new URL(cal);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}

诅咒谷歌的恶搞日历API。