【问题标题】:How to programmatically subscribe a user to a google calendar using javascript?如何使用 javascript 以编程方式为用户订阅谷歌日历?
【发布时间】:2016-04-20 06:02:08
【问题描述】:

嘿,我可以使用 google 日历的 javascript API 对用户进行身份验证和授权。我接下来要做的是为该用户订阅公共日历。我在想我可以用日历的 id 调用 google.gdata.calendar.CalendarEntry 构造函数,但这不起作用

var entry = google.gdata.calendar.CalendarEntry("idOfCalendar");

我还尝试使用 google.gdata.atom.Id("idOfCalendar"); 创建条目 id 的实例并将其添加到 CalendarEntry 构造函数中。使用 set 方法也不起作用。

我使用 InsertEntry 方法添加条目,但出现以下错误

错误:必须提供有效的日历 ID 才能将日历添加到 allcalendars 投影中的收藏夹列表。

我可以使用 google.gdata.calendar.CalendarEventQuery() 访问此日历的事件

用于 javascript 的 google api 没有提供很多示例,任何人都知道我的问题的答案或使用 google calendar api 的好资源?你认为我应该改用 php 还是 jason?

** 编辑 我在 Java Api link 中找到了我想要的示例,所以我尝试了

function addSubscriptionToCalendar() {
    var feedUri = "http://www.google.com/calendar/feeds/default/allcalendars/full";
    var calendarEntry = new google.gdata.calendar.CalendarEntry();
    calendarEntry.setId("nhl_21_%54oronto+%4daple+%4ceafs#sports@group.v.calendar.google.com");
    calendarService.insertEntry(feedUri, calendarEntry, function(){alert("calendar added")}, handleError);
}

但我遇到了同样的错误

【问题讨论】:

    标签: javascript google-calendar-api subscribe


    【解决方案1】:

    您应该使用 owncalendars 供稿来修改/添加经过身份验证的用户的日历条目,而不是 allcalendars。

    【讨论】:

      【解决方案2】:

      听起来您的日历 ID 无效。第二个示例中的 id 似乎是 URL 编码的。尝试使用解码后的值:

      nhl_21_Toronto Maple Leafs#sports@group.v.calendar.google.com

      【讨论】:

        【解决方案3】:

        日历的 gdata API 已关闭;新的方法是通过:https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert

        【讨论】:

          猜你喜欢
          • 2013-07-21
          • 1970-01-01
          • 2018-03-19
          • 2012-07-02
          • 2014-11-14
          • 1970-01-01
          • 2012-02-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多