首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于CalDav API的雅虎日历集成

基于CalDav API的雅虎日历集成
EN

Stack Overflow用户
提问于 2013-02-13 07:40:23
回答 1查看 2.4K关注 0票数 2

我试图访问一个用户的雅虎日历,如果他的用户名和密码是已知的。我找到了一个代码片段,它使用CalDav api来执行任务。代码使用两个库sardine.jar和ical4j.jar。该代码的文档显示,代码将适用于谷歌日历和雅虎日历。只是我们必须相应地将url更改为CalDav服务器。对于google日历,代码可以正常工作,但是当我更改雅虎日历的代码时,它不起作用。我得到了以下错误:

带根源的net.fortuna.ical4j.data.ParserException:第1行中的错误:预期-3,读-1

我认为这是因为google和yahoo的ics文件格式不匹配,或者雅虎没有创建ics文件。当我在浏览器中使用这个url时,我发现了一个google日历的ics文件,而不是来自雅虎。

这是我使用的代码:

代码语言:javascript
复制
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/Calendar//

请让我知道什么是与代码,或我如何获得雅虎日历的ics文件编程。

EN

回答 1

Stack Overflow用户

发布于 2015-01-13 22:15:47

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14848621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档