Uncaught TypeError: Can not read property 'calendar' of undefined

0

I want to create an event in javascript to insert an event in Google Calendar with the following code:

var event = {
  'summary': 'Google I/O 2015',
  'location': '800 Howard St., San Francisco, CA 94103',
  'description': 'A chance to hear more about Google\'s developer products.',
  'start': {
    'dateTime': '2018-03-7T09:00:00-07:00',
    'timeZone': 'Europe/Madrid'
  },
  'end': {
    'dateTime': '2018-03-7T17:00:00-07:00',
    'timeZone': 'Europe/Madrid'
  },
  'recurrence': [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  'attendees': [
    {'email': '[email protected]'},
    {'email': '[email protected]'}
  ],
  'reminders': {
    'useDefault': false,
    'overrides': [
      {'method': 'email', 'minutes': 24 * 60},
      {'method': 'popup', 'minutes': 10}
    ]
  }
};

var request = gapi.client.calendar.events.insert({
  'calendarId': '[email protected]',
  'resource': event
});

request.execute(function(event) {
  appendPre('Event created: ' + event.htmlLink);
});

but I get the following error:

  

Uncaught TypeError: Can not read property 'calendar' of undefined

I think it's because I'm not authorized in the Auth2.0.

    
asked by Antonio Carnerero 04.03.2018 в 19:46
source

1 answer

0

Surely the error occurs on the line

var request = gapi.client.calendar.events.insert({
  'calendarId': '[email protected]',
  'resource': event
});

and this because you probably have not loaded the Google API library for JavaScript. The guide of how to start with this library is in English at link

The guide gives three options

  • Load the "discovery document API" and then assemble the request.
  • Use gapi.client.request
  • Use CORS
  • answered by 04.03.2018 в 23:54