簡體   English   中英

谷歌日歷api asp.net c#

[英]google calendar api asp.net c#

我創建一個新的日歷“測試”,並使用此代碼

 public static CalendarService GetService(string applicationName, string userName, string password)
    {
        CalendarService service = new CalendarService(applicationName);
        service.setUserCredentials(userName, password);
        return service;
    }
    public static void AddEvent(CalendarService service, string title, string contents, string location, DateTime startTime, DateTime endTime)
    {
        Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry();

        // Set the title and content of the entry.
        entry.Title.Text = title;
        entry.Content.Content = contents;

        // Set a location for the event.
        Where eventLocation = new Where();
        eventLocation.ValueString = location;
        entry.Locations.Add(eventLocation);

        When eventTime = new When(startTime, endTime);
        entry.Times.Add(eventTime);

        Uri postUri = new Uri("https://www.google.com/calendar/feeds/test/private/full");

        // Send the request and receive the response:
        AtomEntry insertedEntry = service.Insert(postUri, entry);
    }

AddEvent(GetService("regis-test", vUserName, vPassword), "title", "test", "Sibiu", DateTime.Now, DateTime.Now.AddHours(4));

怎么了 ? 因為此代碼不會將事件添加到他添加到默認日歷的測試日歷中

您需要修改Uri以反映日歷ID。

我已經在我的gmail帳戶上創建了一個測試日歷,並能夠使用以下URI作為日歷來創建日歷事件:

Uri postUri = new Uri("https://www.google.com/calendar/feeds/hsi9s9tlvgkugbub8r42kv9ugk@group.calendar.google.com/private/full");

要找到您的測試日歷的日歷ID,您需要執行以下操作:

在“我的日歷”下的左側菜單中選擇測試日歷,然后按設置。

日歷設定

然后選擇您的日歷:

在此處輸入圖片說明

在下一個屏幕中,您將在“日歷地址”下看到您的日歷ID: 日歷編號

使用您的Uri的ID:

Uri postUri = new Uri("https://www.google.com/calendar/feeds/hsi9s9tlvgkugbub8r42kv9ugk@group.calendar.google.com/private/full");

這是通過測試日歷上的C#代碼創建的日歷事件的屏幕截圖: 條目已添加

暫無
暫無

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

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