Google Calendar API v3 with C# - Unable to insert events.

133 views
Skip to first unread message

Steve Barker

unread,
Mar 1, 2012, 11:02:57 AM3/1/12
to google-ca...@googlegroups.com
Hi there,

I'm trying to create calendar entries using c# but am getting errors.

Here is the essence of the code I'm using:

============================

IAuthenticator authenticator = new OAuth2LeggedAuthenticator("<domain.com>", "<Secret Key>", "<User name for target calendar", "<domain.com>");
var service = new CalendarService(authenticator);
service.Key = "<API Key>";

var e = new Event
{
                            End = new EventDateTime {Date = "2012-02-29"},
                            Organizer = new Event.OrganizerData {Email = "<email address>"},
                            OriginalStartTime = new EventDateTime {Date = "2012-02-29"},
                            Start = new EventDateTime {Date = "2012-02-29"},
                            Summary = "Summary",
};
           
var insertRequest = service.Events.Insert(e, "primary");
var result = insertRequest.Fetch();

============================

The error I'm getting is:

"You must provide a request body if you set ContentLength>0 or SendChunked==true.  Do this by calling [Begin]GetRequestStream before [Begin]GetResponse."

Any help to resolve this gratefully received. I'm finding that documentation online is extremely sparse!

Thanks in advance,

Steve.



Nono

unread,
Mar 1, 2012, 4:55:26 PM3/1/12
to google-ca...@googlegroups.com
you dont use right code to create calendar, your code seem to create calendar, no calendar ....

please read this post, maybe it can help you to create calendar https://groups.google.com/d/topic/google-calendar-api/Zd6EmtysmxM/discussion

hope it help, but you can see this : http://code.google.com/intl/fr-FR/apis/calendar/v3/using.html, where it explain how to create calendar

first you need to be authent

Steve Barker

unread,
Mar 2, 2012, 7:44:25 AM3/2/12
to google-ca...@googlegroups.com
Hi Arnaud,

Thanks for your reply.

We did actually manage to get it working in the end, but the work around was very nasty! Calling the following code before any requests are made does the trick:

var list = service.Events.List("primary");
var feltch = list.Fetch();

I've included a complete listing below in case anyone else finds it useful.

Our next problem is that we can't get recurring tasks working (also included in the code below). Any one spot what I'm doing wrong? The error I'm getting is:

Google.Apis.Requests.RequestError
Missing time zone definition for start time. [400]
Errors [
    Message[Missing time zone definition for start time.] Location[ - ] Reason[required] Domain[global]

This only happens with recurring tasks. Non-recurring tasks go through with no problems.

Thanks in advance,

Steve.

===================

            IAuthenticator authenticator = new OAuth2LeggedAuthenticator("XXX", "XXX", "XXX", "XXX");

            var service = new CalendarService(authenticator);
            service.Key = "XXX";

            var list = service.Events.List("primary");
            var feltch = list.Fetch();

            var start = new EventDateTime();
            start.DateTime = "2012-03-05T10:30:00Z";

            var end = new EventDateTime();
            end.DateTime = "2012-03-05T11:45:00Z";

            var attendee = new EventAttendee();
            attendee.Email = "XXX";

            var e = new Event();

            e.End = end;
            e.Kind = "calendar#event";
            e.Organizer = new Event.OrganizerData { Email = "XXX" };
            e.Start = start;
            e.Summary = "Summary";
            e.Id = null;
            e.ICalUID = null;
            e.Location = "";
            e.Attendees = new List<EventAttendee>();
            e.Attendees.Add(attendee);

            var eventReminder = new EventReminder();
            eventReminder.Method = "popup";
            eventReminder.Minutes = 15;

            e.Reminders = new Event.RemindersData();
            e.Reminders.UseDefault = false;
            e.Reminders.Overrides = new List<EventReminder>();
            e.Reminders.Overrides.Add(eventReminder);

            // Recurrence:
            var recurrence = "DTSTART:20120305T103000Z\r\nDURATION=30M\r\nRRULE:FREQ=DAILY;COUNT=20;INTERVAL=1;WKST=SU";
            e.Recurrence = new List<string>();
            e.Recurrence.Add(recurrence);

            var request = service.Events.Insert(e, "primary");
            request.SendNotifications = false;
            request.Fetch();

========================

--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-calendar-api/-/XbXrFrpFaocJ.

To post to this group, send email to google-ca...@googlegroups.com.
To unsubscribe from this group, send email to google-calendar...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.

Steve Barker

unread,
Mar 2, 2012, 9:39:02 AM3/2/12
to Google Calendar API
I've managed to solve this problem and am now having issues with
recurrence exceptions!

I've started a new post for this one:

http://groups.google.com/group/google-calendar-api/browse_thread/thread/89160e8dbc82bca7?hl=en

Cheers,

Steve.

P.S. Apologies for my typo in the code.

On Mar 2, 12:44 pm, Steve Barker <steve.tremola...@googlemail.com>
wrote:
> >https://groups.google.com/d/topic/google-calendar-api/Zd6EmtysmxM/dis...
>
> > hope it help, but you can see this :
> >http://code.google.com/intl/fr-FR/apis/calendar/v3/using.html, where it
> > explain how to create calendar
>
> > first you need to be authent
>
> > Le jeudi 1 mars 2012 17:02:57 UTC+1, Steve Barker a écrit :
>
> >> Hi there,
>
> >> I'm trying to create calendar entries using c# but am getting errors.
>
> >> Here is the essence of the code I'm using:
>
> >> ============================
>
> >> IAuthenticator authenticator = new OAuth2LeggedAuthenticator("<do**
> >> main.com <http://domain.com>>", "<Secret Key>", "<User name for target
> >> calendar", "<domain.com>");
> >> var service = new CalendarService(authenticator)**;
Reply all
Reply to author
Forward
0 new messages