簡體   English   中英

C#無法使用API​​將事件插入Google日歷

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

當我嘗試向日歷中插入新事件時,我收到錯誤消息:

未找到[404]錯誤[消息[未找到]位置[-]原因[未找到]域[全局]]

我發現我無法訪問與主要對象不同的被叫對象。

這是我的代碼:

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

其中cal_name是要向其中插入事件的日歷的名稱。

如果我將名稱更改為"primary"則效果很好。

我按照以下說明進行了操作,但未做任何更改: LINK

先感謝您

嘗試使用id代替名稱,並檢查是否適合您的情況。

首先,使用CalendarList: list獲取要在其中插入事件的日歷的ID。

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

在此處輸入圖片說明

然后,您現在可以使用其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"
    }
}

@adjuremods

非常感謝您的回答。 我將其從列表字段id而不是summary 它工作完美!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM