将事件添加到“特定”事件带有 GData API 的 Google 日历

发布于 2024-08-20 01:54:57 字数 1025 浏览 1 评论 0原文

我正在尝试将事件添加到谷歌日历中的特定日历,但我只是不知道如何操作。这是我的代码:

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

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

编辑

也许我应该提到,这种功能只有网站管理员才能访问,该网站管理员想要轻松地将约会和注释添加到他的谷歌日历中,所以我自动使用“硬编码”值对其进行了身份验证,因此我确定用户名和密码正确。

I'm trying to add an event to a specific calendar in google calendar and I just don't find how. Here's my code :

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

Can anyone help me out with this one?

Edit

Maybe I should mention that this fonctionnability is only accessible for an administrator of a site which want to easly add rendez-vous and note to his google calendar so I automaticaly authenticated it with "hardcoded" value so I'm sure the username and password are ok.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2024-08-27 01:54:57

您的代码正在使用您指定的用户名和密码的默认 Google 日历。 (即它使用[电子邮件受保护]的默认日历)您可以看到这个是因为 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/private/full"

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

编辑:

我的错误是我提到您还需要在“private”一词之后包含私钥。您实际上不必这样做。我已经验证我可以通过删除私钥成功发布到辅助日历。

Your code is working with the default Google Calendar for your specified user name and password. (IE it is using the default calendar for [email protected]) You can see this because the URI points to "/feed/default/private". If you want to post the event to another calendar the user name must authorized to post to that calendar, and you need to post to THAT calendars private uri.

EDIT:
The default format of this private URL is "http://www.google.com/calendar/feeds/CALENDAR_ID/private/full"

To find the calendar id, it is next Calendar Address in the calendar settings page on Google Calendars. It will appear similar to this:

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

The final URL would be:

EDIT:
"http://www.google.com/calendar/feeds/***************************@group.calendar.google.com/private/full"

This will go in your Uri postUri = new Uri();

EDIT:

My mistake was that I mentioned that you need to also include the private key after the word private. You do not actually have to do this. I have verified that I could successfully post to a secondary calendar by removing the private key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文