谷歌日历API-我如何创建一个快速添加事件使用javascript



我只是在学习Google的日历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-

我认为你需要添加一个事件日期,我想需要的最小数据是"What"one_answers"When"

// 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,应该很清楚要在哪些日期将事件快速添加到

相关内容

  • 没有找到相关文章

最新更新