Recurring event with google Calendar API V3

2,617 views
Skip to first unread message

calendrier cal

unread,
May 5, 2014, 4:14:57 AM5/5/14
to google-ca...@googlegroups.com
Hi everybody ,

i'm trying to manipulate somme specific things with google events, i can add, delete, get all events and put colors on events, But i Have a problem , each time i ty to insert  a recurring event , i get not valid timezone message and i don't know how to fix it :/

This my code :
----------------------------------------------------------------------------------------------------------
public void AddRecurringEvents(Calendar service, Event createdEvent,
            String rule, String Summary, String Location) {

        Event event = new Event();
        // Define Date Time for each start and end time.
        DateTime start = DateTime.parseRfc3339("2014-09-30T10:00:00Z");
        DateTime end = DateTime.parseRfc3339("2014-09-30T10:25:00Z");

        event.setStart(new EventDateTime().setDateTime(start).setTimeZone(
                "Europe/Paris"));
        event.setEnd(new EventDateTime().setDateTime(end).setTimeZone(
                "Europe/Paris"));
        // Setting recurrence
        event.setRecurrence(Arrays.asList(rule));

        try {

            Event recurringEvent = service.events().insert("primary", event)
                    .execute();
            System.out.println(createdEvent.getId());
        } catch (IOException e) {

            e.printStackTrace();
        }

    }
Any ideas how to fix this problem ?? is there something wrong with my code ...

THanks

Neil

unread,
May 7, 2014, 5:07:50 AM5/7/14
to google-ca...@googlegroups.com
Have you tried omitting the setTimeZone?

calendrier cal

unread,
May 9, 2014, 11:37:06 AM5/9/14
to google-ca...@googlegroups.com
yes i tried to delete it and it gaves me this :
{ "code" : 400, "errors" : [ { "domain" : "global", "message" : "Missing time zone definition for start time.", "reason" : "required" } ], "message" : "Missing time zone definition for start time." }


--
You received this message because you are subscribed to a topic in the Google Groups "Google Calendar API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-calendar-api/nrwVHD2IRkU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-calendar...@googlegroups.com.
To post to this group, send email to google-ca...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-calendar-api.
For more options, visit https://groups.google.com/d/optout.

Neil Gerstenberg

unread,
May 9, 2014, 2:24:35 PM5/9/14
to google-ca...@googlegroups.com
Ok... have you checked the time format? The examples I've seen for this (https://developers.google.com/google-apps/calendar/recurringevents) use:

2011-06-03T10:00:00.000-07:00

instead of:


2014-09-30T10:00:00Z

Not sure that would make a difference, but maybe worth a try. And/or this (http://stackoverflow.com/questions/8856468/android-calendar-api-insert-recurring-event):

DateTime startDT = new DateTime(start, TimeZone.getTimeZone("Europe/Paris")); event.setStart(new EventDateTime().setDateTime(startDT).setTimeZone("Europe/Paris"); DateTime endDT = new DateTime(end, TimeZone.getTimeZone("Europe/Paris")); event.setEnd(new EventDateTime().setDateTime(end).setTimeZone("Europe/Paris");


Neil
--
Keep Google Calendar in Pristine Condition with GCalToolkit

Got an iPhone, iPad or iPod Touch? Need to Memorize? Get "Learn Anything" Now for Free!

calendrier cal

unread,
May 12, 2014, 5:50:56 AM5/12/14
to google-ca...@googlegroups.com
Here's what i have done because i saw this exemple too, but here as you see my problem is "startTime"
 each time i define it as a date or datetime i got problems  "(i put where i have problems in bold)
public void AddRecurringEvents(Calendar service, Event createdEvent,
             String Summary, String Location) {

        String[] days = { "SU", "MO", "TU", "WE", "TH", "FR", "SA" };
        String rrule = "RRULE:FREQ=DAILY;WKST=MO;BYDAY=MO";

        Event event = new Event();
        StringBuilder sb = new StringBuilder();
        sb.append(rrule);
       
       
       
        sb.append(days[( startTime).get(java.util.Calendar.DAY_OF_WEEK) - 1]);
        event.setSummary(Summary);
        event.setLocation(Location);

       
        // Define Date Time for each start and end time.
        DateTime start = new DateTime(startTime.getTime(),
                TimeZone.getTimeZone("UTC"));
        event.setStart(new EventDateTime().setDateTime(start)
                .setTimeZone("UTC"));
        DateTime end = new DateTime(endTime.getTime(),
                TimeZone.getTimeZone("UTC"));
        event.setEnd(new EventDateTime().setDateTime(end).setTimeZone("UTC"));
       
        // Setting recurrence
        ArrayList<String> recur = new ArrayList<String>();
        recur.add(sb.toString());
        event.setRecurrence(recur);

        try {
            createdEvent = service.events().insert("primary", event).execute();
        } catch (IOException e) {

            e.printStackTrace();
        }
    }

}

Neil

unread,
May 21, 2014, 5:04:50 AM5/21/14
to google-ca...@googlegroups.com
Funnily enough I just ran into this myself this week...  and found an answer here: http://stackoverflow.com/questions/16372033/trying-to-create-an-all-day-event-using-google-calendar-api-v3-for-java-causes-a

The problem seems to be caused by the conversion between the Google DateTime & Java Date since the latter has no equivalent for Joda's "localDate". I tried Joda and Apache Commons Lang3 but neither worked correctly. The string approach in the SO link above works fine though.

Neil



On Monday, 5 May 2014 10:14:57 UTC+2, calendrier cal wrote:
Reply all
Reply to author
Forward
0 new messages