Help! Uncaught TypeError: Cannot read property 'events' of undefined

2,651 views
Skip to first unread message

kuko...@gmail.com

unread,
Jan 8, 2015, 7:20:26 AM1/8/15
to google-ca...@googlegroups.com
I'm using API JavaScript Client with Calendar, but I have an error!
Perhaps somebody knows what is happening.

Thanks a lot.

This is the error:

Uncaught TypeError: Cannot read property 'events' of undefined

And this is my code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />       


        var apiKey = 'xxxxxxx';
   

        function makeRequest(){
            console.log('Google Calendar API loaded.');

            gapi.client.calendar.events.list({'calendarId' : 'xxxxxxxx'}).then(function(resp){ //This line throws the error
                console.log(resp.result.item);
            }, function(reason){
                console.log('Error '+reason.result.error.message)
;
            });
  
        }
   
   
        function init(){
            gapi.client.setApiKey(apiKey);
            gapi.client.load('Calendar API', 'v3').then(
                makeRequest()
            );
        }
 
    </script>

    <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=init"></script> 

  </head>
 
  <body>
   
   
  </body>
</html>

Matt Erickson

unread,
Jan 8, 2015, 8:00:39 AM1/8/15
to google-ca...@googlegroups.com
Looks like gapi.calendar is undefined. Maybe you don't have the library losses on the page? Do a console.log on that our a debugger; so you can see if you have access to it. Any other console errors?

Matt Erickson

unread,
Jan 8, 2015, 8:04:20 AM1/8/15
to google-ca...@googlegroups.com

kuko...@gmail.com

unread,
Jan 8, 2015, 10:41:48 AM1/8/15
to google-ca...@googlegroups.com
This is the other error in console:


I thought that it wasn`t important, but now, I don't know...

I learned to use this client in this page:
https://developers.google.com/api-client-library/javascript/start/start-js and in this other:
https://developers.google.com/api-client-library/javascript/dev/dev_jscript?hl=es

Thank a lot for your help!

kuko...@gmail.com

unread,
Jan 8, 2015, 10:44:15 AM1/8/15
to google-ca...@googlegroups.com

Excuse me! The error:

Matt Erickson

unread,
Jan 8, 2015, 10:47:56 AM1/8/15
to google-ca...@googlegroups.com
You are asking for the api incorrectly:

gapi.client.load('calendar', 'v3', function() {

is the correct "name"

This blog post may help you as well (unaffiliated with myself)

kuko...@gmail.com

unread,
Jan 8, 2015, 10:59:37 AM1/8/15
to google-ca...@googlegroups.com
I also tried defining the callback function of gapi.client.load instead of a promise, in this case, the first error is eliminated, but the second error continue:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

I think that this error isn't in the code.

kuko...@gmail.com

unread,
Jan 8, 2015, 11:03:57 AM1/8/15
to google-ca...@googlegroups.com
This error perhaps is saying me this:

The JavaScript client library does not support local pages and the file:// protocol.

https://developers.google.com/api-client-library/javascript/help/faq?hl=es
Reply all
Reply to author
Forward
0 new messages