Petar-KreŇ°imir Petar-KreŇ°imir - 1 year ago 107
Javascript Question

Uncaught TypeError: Cannot read property 'calendar' of undefined - Google Calendar API

I'm playing around with OAuth2 and Calendar API using Javascript. I'm using a following test function to see if the event is being added to the calendar (after authentication of the user by the API).

function addTestEvent()

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': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles'
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles'

var request ={
'calendarId': 'primary',
'resource': event

request.execute(function(event) {

I'm using the example from the documentation.

In the console, I get the message saying calendar is undefined (referring to the var request = ... line)

Uncaught TypeError: Cannot read property 'calendar' of undefined

I have included the

<script src=""></script>

in my page. What am I doing wrong here?

Also, is there a tutorial or a good example that would help me understand the whole process, because the docs are kinda thin in my opinion?

Answer Source

You should provide more of your code because if it's saying calendar of undefined then I'm assuming the client for gapi.client wasn't instantiated correctly.

Likely need to make sure all the authing is done before you try to access the client as the client needs to verify the credentials.

And this documentation example should be a fairly straight copy paste and modify to get a working example:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download