是否可以使用 ical4j 创建或更新事件

Is it possible to create or update events using ical4j

我创建了一个从 Yahoo 获取日历数据 (VEvents) 的客户端。现在我需要能够更新现有事件或创建新事件并 'publish' 它,以便在 Yahoo 日历中可见。

这可以用 ical4j 完成吗,还是我需要找到其他方法来完成?

好的,我找到了一种方法。问题是对于 CalDavCollection,您实际上不能直接添加事件,您需要将其作为日历添加。有效的代码:

public void addEvent(VEvent event, VTimeZone timezone){
                    try {
                        Calendar calendar = new Calendar();
                        calendar.getProperties().add(new ProdId(prodId));
                        calendar.getProperties().add(Version.VERSION_2_0);
                        calendar.getProperties().add(CalScale.GREGORIAN);
                        calendar.getComponents().add(event);
                        collection.add(httpClient, calendar);
                    } catch (CalDAV4JException e) {
                        e.printStackTrace();
                    }

    }

中的'prodId'
calendar.getProperties().add(new ProdId(prodId));

是日历提供商的 prodId(在我的例子中是 PRODID://Yahoo//Calendar//EN)

该集合是 CalDavCollecion 的实例,它与特定的日历相关,因此只需添加带有新事件的日历即可将其添加到服务器的正确日历中。