当我尝试在我的GCalendar上插入新事件时,显然我遇到了问题。网站返回创建的事件:未定义,我正确地建立了连接和身份验证,并且可以列出我的实际日历事件,但仍然无法插入新事件
var test = {
"summary":"TEST",
"description":"TEST",
"start":
{
"dateTime":"2017-01-01T12:00:00.000+01:00"
},
"end":
{
"dateTime":"2017-01-01T12:30:00.000+01:00"
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': test
});
request.execute(function(test) {
appendPre('Event created: ' + test.htmlLink);
});
任何解决方案?
答案 0 :(得分:1)
您需要将Events.insert代码括在一个函数中,该函数将在授权(use the JS Quickstart)完成后调用。
function loadCalendarApi() {
gapi.client.load('calendar', 'v3', insertEvent);
}
//this is the function that will be called
function insertEvent() {
var event = {
'summary': 'Google I/O 2017',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2017-01-20T09:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
.
.
request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
console.log("Event added to Calendar");
});
}
完整的工作代码is here。使用您自己的CLIENT_ID。