如何使用javascript以编程方式订阅用户到谷歌日历?

Dev*_*man 13 javascript google-calendar-api subscribe

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

var entry = google.gdata.calendar.CalendarEntry("idOfCalendar");
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

javascript的谷歌api没有提供很多例子,任何人都知道我的问题的答案或使用谷歌日历API的良好资源?你认为我应该使用php或jason吗?

**编辑我在Java Api 链接中找到了一个我想要的例子,所以我试过了

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);
}
Run Code Online (Sandbox Code Playgroud)

但我得到了同样的错误

小智 3

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