Google Calendar API - How do I create a QUICK ADD event using javascript?
I'm just learning Google's Calendar API and can't figure out how to create a Quick Add Event using javascript. Is this possible? Are there any examples or documentation?
Here's what's not working - Rather than creating an event tomorrow at 10am called "Coffee", the following code creates an event set for whatever time I posted it, and puts "Coffee tomorrow 10am" in the description field.
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.creat开发者_Python百科e("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);
}
What am I doing wrong? What am I doing right?
Thanks!
-alex-
I think you need to add an event date the minimum data needed I guess is "What" and "When"
i.e
// 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);
So if you change your code above to
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);
}
That should work, take note I changed the setContent
to setTitle
------------------------ EDIT -----------------------------
The answer above is for adding events normally, initially did not get the question. But for addning quick events it should be
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);
}
take note of the setContent it should be clear what dates you want to quick add the event to
精彩评论