0
votes

I have an app that read a public google calendar feed and populate a listview with the events in this calendar. The problem is that I was using this url to get the feed http://www.google.com/calendar/feeds/[CalendarID]/public/full?orderby=starttime&max-results=150&singleevents=true&sortorder=ascending&futureevents=true

It seems that now that the google calendar api v2 has been discontinued, this url is not valid, and throws a "Forbidden Error 403", so that when I try to use it in my app, itcrashes.

Here are my code to parse the xml in that url:

public ArrayList<Agenda> parse() {

    ArrayList<Agenda> events = null;
    XmlPullParser parser = Xml.newPullParser();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    try
    {
        parser.setInput(this.getInputStream(), null);
        int parserEvent = parser.getEventType();
        Agenda event = null;

        while (parserEvent != XmlPullParser.END_DOCUMENT)
        {
            String etiqueta = null;

            switch (parserEvent)
            {
                case XmlPullParser.START_DOCUMENT:
                    events = new ArrayList<Agenda>();
                    break;

                case XmlPullParser.START_TAG:
                    etiqueta = parser.getName();

                    if (etiqueta.equals("entry"))
                    {
                        event = new Agenda();
                    }
                    else if (event != null)
                    {
                        if (etiqueta.equals("title")){
                            String titol = parser.nextText();
                            event.setTitol(titol);
                            Log.d("Titol Event", titol);
                        }
                        else if (etiqueta.equals("where")){
                            String lloc = parser.getAttributeValue(null, "valueString");
                            event.setLloc(lloc);
                        }
                        else if (etiqueta.equals("when")){
                            Date iniciEvent = null;
                            Date finalEvent = null;
                            String dataInici = (parser.getAttributeValue(null, "startTime"));
                            Log.d("DATA INICI", dataInici);
                            String dataFinal = (parser.getAttributeValue(null, "endTime"));
                            if(dataFinal == null){
                                break;
                            }
                            Log.d("DATA FINAL", dataFinal);
                            try {
                                iniciEvent = formatter.parse(dataInici);
                                event.setData(iniciEvent);
                                formatHoraCorrecta = true;
                                event.setAllDay(false);
                            } catch (ParseException e) {
                                // TODO Auto-generated catch block
                                Log.d("ERROR FORMAT DATA", e.toString());
                                formatHoraCorrecta = false;
                                event.setAllDay(true);
                            }

                            if(!formatHoraCorrecta){
                                dataInici = dataInici + "T00:00:00";
                                iniciEvent = formatter.parse(dataInici);
                                event.setData(iniciEvent);
                                dataFinal = dataFinal + "T00:00:00";
                                finalEvent = formatter.parse(dataFinal);
                                event.setDataFinal(finalEvent);
                            }else{
                                finalEvent = formatter.parse(dataFinal);
                                event.setDataFinal(finalEvent);
                            }

                        }else  if(etiqueta.equals("content")){
                            event.setDescripcio(parser.nextText());
                        }

                    }
                    break;

                case XmlPullParser.END_TAG:
                    etiqueta = parser.getName();

                    if (etiqueta.equals("entry") && event != null)
                    {
                        events.add(event);
                    }
                    break;
            }

            parserEvent = parser.next();
        }
    }catch (Exception ex){
        Log.d("Exception ex", ex.toString());
        throw new RuntimeException(ex);
    }
    return events;
}

I find that this URL shows now the calendar feed http://www.google.com/calendar/feeds/[CalendarID]/public/basic?orderby=starttime&max-results=150&singleevents=true&sortorder=ascending&futureevents=true but actually the way the info is shown is totally different, so that that code doesn't work.

Is there a way I could parse the info from google calendar v3 feed, in a similar way I did it before or I have to use other methods?

1

1 Answers

0
votes

In Calender v2, this code will work as the response you receive is in xml format.

But for Calender v3, the parsing method has to be changed to match the new response as specified in the Google Calendar API Version 3.0 Migration Guide.

You can also refer to this question: How to Parse the this JSON Response in JAVA

Hope that helps!