我只是在学习Google的Calendar API,无法弄清楚如何使用javascript创建快速添加事件。这可能吗?有没有例子或文件?
这是什么不起作用 - 以下代码不是在明天上午10点创建一个名为“Coffee”的事件,而是在我发布它的任何时间创建一个事件集,并在描述字段中放置“Coffee tomorrow 10am”。
function createEvent() {
var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');
var feedUri = 'http://www.google.com/calendar/feeds/my-calendar-url/private/full';
var entry = new google.gdata.calendar.CalendarEventEntry();
entry.setContent(new google.gdata.atom.Text.create("Coffee tomorrow 10am"));
entry.setQuickAdd(true);
var callback = function (result) {
$('#panel').html('event created!');
}
var handleError = function (error) {
$('#panel').html(error);
}
calendarService.insertEntry(feedUri, entry, callback, handleError, google.gdata.calendar.CalendarEventEntry);
}
我做错了什么?我做得对吗?
谢谢!
-alex-
答案 0 :(得分:0)
我认为您需要添加一个事件日期所需的最小数据我猜是“什么”和“何时”
即
// Create a When object that will be attached to the event
var when = new google.gdata.When();
// Set the start and end time of the When object
var startTime = google.gdata.DateTime.fromIso8601("2008-02-10T09:00:00.000-08:00");
var endTime = google.gdata.DateTime.fromIso8601("2008-02-10T10:00:00.000-08:00");
when.setStartTime(startTime);
when.setEndTime(endTime);
// Add the When object to the event
entry.addTime(when);
因此,如果您将上面的代码更改为
function createEvent() {
var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');
var feedUri = 'http://www.google.com/calendar/feeds/my-calendar-url/private/full';
var entry = new google.gdata.calendar.CalendarEventEntry();
entry.setTitle(new google.gdata.atom.Text.create("Coffee tomorrow 10am"));
var when = new google.gdata.When();
var startTime = google.gdata.DateTime.fromIso8601("2008-02-10T09:00:00.000-08:00");
var endTime = google.gdata.DateTime.fromIso8601("2008-02-10T10:00:00.000-08:00");
when.setStartTime(startTime);
when.setEndTime(endTime);
entry.addTime(when);
var callback = function (result) {
$('#panel').html('event created!');
}
var handleError = function (error) {
$('#panel').html(error);
}
calendarService.insertEntry(feedUri, entry, callback, handleError, google.gdata.calendar.CalendarEventEntry);
}
这应该有用,请注意我已将setContent
更改为setTitle
------------------------编辑------------------- ---------- 强>
上面的答案是正常添加事件,最初没有得到问题。但是为了添加快速事件,它应该是
function createEvent() {
var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');
var feedUri = 'http://www.google.com/calendar/feeds/my-calendar-url/private/full';
var entry = new google.gdata.calendar.CalendarEventEntry();
entry.setContent(new google.gdata.atom.Text.create("Coffee June 25 10am-10:30am"));
entry.setQuickAdd(true);
var callback = function (result) {
$('#panel').html('event created!');
}
var handleError = function (error) {
$('#panel').html(error);
}
calendarService.insertEntry(feedUri, entry, callback, handleError, google.gdata.calendar.CalendarEventEntry);
}
注意setContent,应该明确要将事件快速添加到
的日期