Triti
Triti

Reputation: 151

C# Can't insert event to Google Calendar using API

when I'm trying to insert a new event to my calendar I recive error:

Not Found [404] Errors [Message[Not Found] Location[ - ] Reason[notFound] Domain[global]]

I figured out that I have no access to a diffrent callendar than primary.

Here is my code:

Event newEvent = new Event()
{
    Summary = ee[0],
    Start = new EventDateTime()
    {
        DateTime = DateTime.Parse(ee[2] + "T" + ee[3] + ":00+02:00")
    },
    End=new EventDateTime()
    {
        DateTime=DateTime.Parse(ee[4] + "T" + ee[5] + ":00+02:00")
    },
    Location=ee[2],
};
EventsResource.InsertRequest ins = service.Events.Insert(newEvent, nazwa_cal);
Event doins = ins.Execute();
Console.WriteLine("Event created: {0}", doins.HtmlLink);

where cal_name is the name of my calendar I want to insert event to.

If I change the name to "primary" it works perfecty.

I followed this instructions but nothing changed: LINK

Thank You in advance

Upvotes: 0

Views: 719

Answers (2)

Triti
Triti

Reputation: 151

@adjuremods

Thank You very much for your answer. I follwed it and chose from the list field id instead of summary. It works perfect!

Upvotes: 0

adjuremods
adjuremods

Reputation: 2998

Try to use the id instead of the name and check if this will work in your case.

First, get the Id of the calendar in where you want to insert your event by using the CalendarList: list

GET https://www.googleapis.com/calendar/v3/users/me/calendarList?maxResults=5&key={YOUR_API_KEY}

enter image description here

Then you can now insert to this event by using its Id.

POST https://www.googleapis.com/calendar/v3/calendars/google.comXXXXXXXXXX9778%40group.calendar.google.com/events?key={YOUR_API_KEY}

{
    "end": {
        "dateTime": "2016-10-15T8:00:00",
        "timeZone": "Asia/Manila"
    },
    "start": {
        "dateTime": "2016-10-15T6:00:00",
        "timeZone": "Asia/Manila"
    }
}

Upvotes: 1

Related Questions