【问题标题】:Adding an Event to a "specific" Google Calender with GData API使用 GData API 将事件添加到“特定”Google 日历
【发布时间】:2011-01-10 03:37:37
【问题描述】:

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

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

谁能帮我解决这个问题?

编辑

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

【问题讨论】:

    标签: c# asp.net gdata-api


    【解决方案1】:

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

    编辑: 此私有 URL 的默认格式为“http://www.google.com/calendar/feeds/CALENDAR_ID/private/full

    要查找日历 ID,它是 Google 日历日历设置页面中的下一个日历地址。它看起来类似于:

    “***************************@group.calendar.google.com”

    最终到达网址是:

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

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

    编辑:

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

    【讨论】:

    • 非常感谢 DanJo519。我现在就试试!!
    • 我试过了,还是报错;请求执行失败:google.com/calendar/feeds/blablabla@group.calendar.google.com/private-PRIVATE_KEY/full。我不明白。最后我尝试了“完整”或“基本”(基本是谷歌默认提供的,但我也尝试过完整的,因为你这么说。无论如何,没有人工作:(
    • 我已经对我的答案进行了修改。您实际上不需要包含 -PRIVATE_KEY。假设您对日历具有​​写入权限,则删除它将允许您发布。我已经用我的一个辅助日历成功地测试了这一点。
    • 那么您仍然看到“执行请求失败”?当我说您首先需要对日历具有​​写入权限时,Google 允许共享辅助日历,以便多人可以向其中添加事件。您需要确保要添加事件的日历可以通过您传递给 CalendarService 的用户名添加事件。您可以通过检查 Google 日历设置的共享选项卡上的日历权限来执行此操作。您设置的用户名应具有“进行更改”权限。
    • 你不应该这样做。我已经复制了您上面提供的代码,只替换了用户名、密码和 postUri。我的日历不是共享的,只能由我正在与之进行身份验证的用户(也是用户)共享和访问,并且我能够成功地发布到该日历。如果您仍然遇到问题,您可能需要提供此代码导致的完整异常。另外,我注意到你有 DateTime.now 而不是 DateTime.Now(注意大写 N),但这会导致编译错误,所以我猜这不是问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 2014-03-24
    • 1970-01-01
    相关资源
    最近更新 更多