gpt4 book ai didi

java - 使用 CalDav API 集成雅虎日历

转载 作者:太空宇宙 更新时间:2023-11-04 07:48:49 28 4
gpt4 key购买 nike

如果用户的用户名和密码已知,我将尝试访问该用户的雅虎日历。我找到了一个使用 CalDav api 来完成任务的代码片段。代码使用 2 个库 sardine.jar 和 ical4j.jar。该代码的文档表明该代码适用于谷歌日历和雅虎日历。只是我们必须相应地更改 CalDav 服务器的 url。代码适用于谷歌日历,但当我更改雅虎日历的代码时,它不起作用。我收到以下错误:

Stacktrace:] 以及根本原因net.fortuna.ical4j.data.ParserException:第 1 行错误:预期 [-3],读取 [-1]

我认为这是由于google和yahoo的ics文件格式不匹配或者没有创建yahoo的ics文件。当我从浏览器而不是雅虎使用此网址时,我发现了谷歌日历的 ics 文件。

这是我使用的代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;

import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.filter.Filter;
import net.fortuna.ical4j.filter.PeriodRule;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.Period;
import net.fortuna.ical4j.model.Property;
import com.googlecode.sardine.Sardine;
import com.googlecode.sardine.SardineFactory;

public class sardineMain {
@SuppressWarnings("deprecation")



public static void main(String[] args) throws Exception {

Sardine sardine = SardineFactory.begin("Email","password");

String url= "https://www.google.com/calendar/dav/emailid@gmail.com/events/";

java.util.Calendar start = java.util.Calendar.getInstance();
java.util.Calendar end = java.util.Calendar.getInstance();
end.add(java.util.Calendar.MONTH, 1);

//Fri May 25 08:56:36 KST 2012==Mon Jun 25 08:56:36 KST 2012

Period period = new Period(new DateTime(start.getTime()),new DateTime(end.getTime()) );
Filter filter = new Filter(new PeriodRule(period));


//Collection<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();


InputStream EventStream = sardine.get(url);
BufferedReader br = new BufferedReader(new InputStreamReader(EventStream));
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(br);


List eventsToday = (List) filter.filter(calendar.getComponents(Component.VEVENT));
CalanderQueryOutput caldavOutput = new CalanderQueryOutput();

for (Iterator i = eventsToday.iterator(); i.hasNext();) {

Component component = (Component) i.next();


String CreatedS = component.getProperty(Property.CREATED).toString().trim();
String SummaryS = component.getProperty(Property.SUMMARY).toString().trim();
String StatusS = component.getProperty(Property.STATUS).toString().trim();
String StartDateS = component.getProperty(Property.DTSTART).toString().trim();
String EndDateS = component.getProperty(Property.DTEND).toString().trim();

/*System.out.println(CreatedS);
System.out.println(SummaryS);
System.out.println(StatusS);
System.out.println(StartDateS);
System.out.println(EndDateS);*/
System.out.println(component);


}
}

这些是网址:

谷歌日历:https://www.google.com/calendar/dav/ <>@gmail.com/events/

雅虎!日历:https://caldav.calendar.yahoo.com/dav/ <>@yahoo.es/日历//

请让我知道代码有什么问题,或者我如何以编程方式获取雅虎日历的 ics 文件。

最佳答案

关于java - 使用 CalDav API 集成雅虎日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14848621/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com