如何使用 JavaScript 以编程方式为用户订阅 Google 日历?
嘿,我可以使用 google calendar 的 javascript API 对用户进行身份验证和授权。我接下来要做的就是为该用户订阅公共日历。我想我可以用日历的 id 调用 google.gdata.calendar.CalendarEntry 构造函数,但这不起作用
var entry = google.gdata.calendar.CalendarEntry("idOfCalendar");
我还尝试使用 google.gdata.atom.Id("idOfCalendar" 创建条目 id 的实例);并将其添加到 CalendarEntry 构造函数中。使用 set 方法也不起作用。
我使用 InsertEntry 方法添加条目,但出现以下错误
错误:必须提供有效的日历 ID 才能将日历添加到所有日历投影中的收藏夹列表。
我可以使用 google.gdata.calendar.CalendarEventQuery() 访问此日历的事件
用于 javascript 的 google api 没有提供很多示例,有人知道我的问题的答案,或者使用 google calendar 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#[email protected]");
calendarService.insertEntry(feedUri, calendarEntry, function(){alert("calendar added")}, handleError);
}
,但遇到了同样的错误
Hey i'm able to authenticate and authorize a user with the javascript API for google calendar. what i want to do next is subscribe that user to a public calendar. I was thinking i could just call the google.gdata.calendar.CalendarEntry constructor with the id of the calendar but that didn't work
var entry = google.gdata.calendar.CalendarEntry("idOfCalendar");
i also tried creating an instance of a entry id with google.gdata.atom.Id("idOfCalendar"); and adding that to the CalendarEntry constructor. Using the set methods didn't work either.
I use the InsertEntry method to add the entry but i get the following error
Error: Valid calendar id must be supplied for adding calendar to favorites list in allcalendars projection.
I can access the events of this calendar using google.gdata.calendar.CalendarEventQuery()
The google api for javascript doesn't give a lot of examples anyone know the answer to my problem or a good resource for working with the google calendar api? do you think i should be using php or jason instead?
** Edit
I found an example of what I want in the Java Api link so i tried
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#[email protected]");
calendarService.insertEntry(feedUri, calendarEntry, function(){alert("calendar added")}, handleError);
}
but i got the same error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用自己的日历 feed 来修改/添加经过身份验证的用户的日历条目,而不是所有日历。
You should be using owncalendars feed to modify/add calendar entry for the authenticated user not allcalendars.
听起来您的日历 ID 无效。第二个示例中的 id 似乎是 URL 编码的。尝试使用解码值:
nhl_21_Toronto Maple Leafs#[电子邮件受保护]
Sounds like your calendar id is invalid. The id from your second example appears to be URL encoded. Try using the decoded value:
nhl_21_Toronto Maple Leafs#[email protected]
日历的 gdata API 已关闭;执行此操作的新方法是通过:https://developers. google.com/google-apps/calendar/v3/reference/calendarList/insert
The gdata API for calendars has been switched off; the new way to do this is via: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert