使用GData API将事件添加到"特定"Google日历

Sim*_*gré 5 c# asp.net gdata-api

我正在尝试将事件添加到Google日历中的特定日历中,而我却找不到如何.这是我的代码:

        CalendarService service = new CalendarService("MyTEst");
        service.setUserCredentials("Username", "Password");
        EventEntry entry = new EventEntry();

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

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

        When eventTime = new When(DateTime.now, DateTime.now.AddDays(2));
        entry.Times.Add(eventTime);

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

        // Send the request and receive the response
        AtomEntry insertedEntry = service.Insert(postUri, entry);
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题吗?

编辑

也许我应该提一下,这个功能只适用于想要轻松添加rendez-vous并注意到他的谷歌日历的网站管理员,所以我自动用"硬编码"值验证它,所以我确定用户名和密码是好.

Dan*_*eph 6

您的代码正在使用默认Google日历作为指定的用户名和密码.(IE使用username@gmail.com的默认日历)您可以看到这一点,因为URI指向"/ feed/default/private".如果您要将活动发布到另一个日历,则必须授权用户名发布到该日历,并且您需要发送到日历私有uri.

编辑:此私人网址的默认格式为" http://www.google.com/calendar/feeds/CALENDAR_ID/private/full "

要查找日历ID,Google日历上的日历设置页面中的下一个日历地址.它看起来与此类似:

"***************************@group.calendar.google.com"

最终的URL将是:

编辑:" http://www.google.com/calendar/feeds/***************************@group.calendar.google .COM /私营/全"

这将进入你的 Uri postUri = new Uri();

编辑:

我的错误是我提到你需要在私有一词之后加入私钥.你实际上不必这样做.我已经通过删除私钥验证我可以成功发布到辅助日历.