Question

I am trying to access yahoo calendar of a user if his username and password are known. I found a code snippet which uses CalDav api to do the task. Code uses 2 libraries sardine.jar and ical4j.jar. The documentation of that code says that code will work for google calendar and yahoo calendar. Only we have to change the url to the CalDav server accordingly. Code works fine for google calendar but when i am changing that code for yahoo calendar, its not working. I got the following error:

Stacktrace:] with root cause net.fortuna.ical4j.data.ParserException: Error at line 1:Expected [-3], read [-1]

I think it was due to the mismatch of ics file formats of google and yahoo or there is no ics file for yahoo is created. I found an ics file of google calendar when i am using this url from a browser but not from yahoo.

This is the code i used:

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);


   }
       }

these are the urls:

Google calendar: https://www.google.com/calendar/dav/<>@gmail.com/events/

Yahoo! Calendar: https://caldav.calendar.yahoo.com/dav/<>@yahoo.es/Calendar//

please let me know what is worng with the code or how can i get ics file of yahoo calendar programmatically.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top