繁体   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