[英]Uncaught TypeError: Cannot read property 'calendar' of undefined - Google Calendar API
I'm playing around with OAuth2 and Calendar API using Javascript. 我正在使用Javascript处理OAuth2和Calendar API。 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).
我正在使用以下测试功能来查看是否将事件添加到日历中(通过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 = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});
request.execute(function(event) {
alert(event.htmlLink);
alert("called?");
});
}
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) 在控制台中,我收到消息说日历未定义(指的是var request = ...行)
Uncaught TypeError: Cannot read property 'calendar' of undefined
I have included the 我已经包括了
<script src="https://apis.google.com/js/api.js"></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? 另外,由于我觉得这些文档太薄了,是否有一个教程或一个很好的示例可以帮助我理解整个过程?
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. 您应该提供更多的代码,因为如果说未定义的
calendar
,那么我假设gapi.client
的client
未正确实例化。
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: https://developers.google.com/calendar/quickstart/js 这个文档示例应该是相当简单的复制粘贴,并进行修改以得到一个有效的示例: https : //developers.google.com/calendar/quickstart/js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.