【问题标题】:Google Calendar API - How do I create a QUICK ADD event using javascript?Google Calendar API - 如何使用 javascript 创建 QUICK ADD 事件?
【发布时间】:2011-06-23 19:59:18
【问题描述】:

我刚刚学习 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);

}

我做错了什么?我做对了什么?

谢谢!

-亚历克斯-

【问题讨论】:

    标签: javascript google-api google-calendar-api


    【解决方案1】:

    我认为您需要添加一个事件日期,我猜需要的最少数据是“什么”和“何时”

    // 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 应该清楚你想快速添加事件的日期

    【讨论】:

    • 嘿雷蒙德,谢谢你的回答。快速添加的重点不是我不需要指定单独的内容/时间吗?它从字符串中解释它吗?
    • 再次感谢您。但是您的代码解决了创建事件的问题,但我希望创建一个“QuickAdd”事件。有什么想法吗?
    • 我还记得我之前的 .Net API 有问题,所以我将 http 更改为 https,如果这解决了问题,请告诉我,以便我更新答案
    • 我没有收到错误,我得到的结果与我预期的不同。我想在一个字符串中创建一个带有标题/时间的事件(快速添加)。但是我上面的代码所做的是在创建时使用我的字符串作为描述创建一个事件,而不是从字符串中推断出标题/时间。
    • 您能否将文本改为“Coffee June 25 10am-10:30am”。我在我的实例中尝试过它有效。看起来“明天”无法破译
    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多