After all the work I put into creating a server-side script to add events in Google Calendar, it turns out that due to security reasons I have to go the AJAX route.  I should have gone with my gut feeling to do so in the beginning. :/

I created a javascript object for my calendar interactions.  The javascript API docs are all goofed up (for instance, I find no direct link from the Data API Guide page for the current 2.0 version of the javascript docs – I had to do a separate google search) so a lot of this was trial and error.  Hopefully it’s  helpful, since I couldn’t find a solid example in the google-sphere.

The app completes the transaction with Google Calendar, then saves data to a local database.  Unfortunately, I’m still not in the habit of commenting my code. :)

Login and Logout

//Login needs to happen before transactions,
//usually via a login button on the web page
function logMeIn() {
    scope = "";
    var token = google.accounts.user.login(scope);

function logMeOut() {
  scope = "";
  if (google.accounts.user.checkLogin(scope)) {

Javascript “oCal” object

//Google Calendar object constructor
var oCal = function(type, entryId) {

  var myService;
  var updater = {};

  var eid = entryId; //global variable defined previously
  var feedUrl = '';

  function setupMyService() {
    myService = new google.gdata.calendar.CalendarService('exampleApp-exampleApp-1');

  //startdate and enddate need to be formatted in ISO = "2007-09-23T18:00:00.000Z"
  function createEvent(startdate, enddate, subject, summary, name, address) {
    var entry = new google.gdata.calendar.CalendarEventEntry({
      title: {
        type: 'text',
        text: subject
      content: {
        type: 'text',
        text: summary
      locations: [{
        rel: 'g.event',
        label: 'Event Location',
        valueString: name+', ' + address
      times: [{
        startTime: google.gdata.DateTime.fromIso8601(startdate),
        endTime: google.gdata.DateTime.fromIso8601(enddate)


    return entry;

  var callback = function(result) {
    alerter('Calendar updated, now saving event');

  function handleEntry(result) {
    var entry = result.entry;


    entry.updateEntry(handleUpdateEntry, handleError);


  function handleDelete(result) {
    result.entry.deleteEntry(handleDeletedEntry, handleError);

  function handleUpdateEntry(result) {
    alerter(result.entry.getTitle().getText() + ' saved');

  function handleDeletedEntry(result) {
    alerter('Calendar entry deleted');

  function handleError(e) {
   alert('Error: ' + (e.cause ? e.cause.statusText : e.message));

  this.addEvent = function(startdate, enddate, subject, summary, name, address) {

    var newEntry = createEvent(startdate, enddate, subject, summary, name, address);

    myService.insertEntry(feedUrl, newEntry, callback, handleError, google.gdata.calendar.CalendarEventEntry);

  this.updateEvent = function(startdate, enddate, subject, summary, name, address) {

    updater = {
      sdate: startdate,
      edate: enddate,
      title: subject,
      content: summary,
      location: name + ', ' + address

    myService.getCalendarEventEntry(eid, handleEntry, handleError);     


  this.deleteEvent = function() {

    myService.getCalendarEventEntry(eid, handleDelete, handleError);