Calendar API gives an error while inserting events using events.insert: There was an error contacting the Calendar service: Error: Missing end time
Calendar API gives an error while inserting events using events.insert: There was an error contacting the Calendar service: Error: Missing end time
我使用了快速入门中的代码示例,并尝试使用 - https://developers.google.com/calendar/v3/reference/events/insert#examples
上的示例插入事件
我检查了网络上可用的资源,其中 none 似乎对我有用(将 googleapis 包降级到版本 24.0.0 或使用不同的方式编写插入事件)。
这是当前addEvents函数的代码-
function addEvents(auth){
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",
},
"recurrence": [
"RRULE:FREQ=DAILY;COUNT=2"
],
"reminders": {
"useDefault": false,
"overrides": [
{"method": "email", "minutes": 24 * 60},
{"method": "popup", "minutes": 10},
],
},
};
//console.log(event)
var calendar = google.calendar("v3");
calendar.events.insert({
auth: auth,
calendarId: "primary",
resource: event,
}, function(err, event) {
if (err) {
console.log("There was an error contacting the Calendar service: " + err);
return;
}
console.log("Event created: %s", event.htmlLink);
});
}
和listEvents函数在同一行-
function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
auth: auth,
calendarId: 'primary',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime'
},
function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var events = response.items;
if (events.length == 0) {
console.log('No upcoming events found.');
}
else {
console.log('Upcoming 10 events:');
for (var i = 0; i < events.length; i++) {
var event = events[i];
var start = event.start.dateTime || event.start.date;
console.log('%s - %s', start, event.summary);
}
}
});
}
谁能帮我解决这个问题?
谢谢!
这些是解决问题所需要做的事情 -
var {google} = require('googleapis');
而不是 var google = require('googleapis');
写var OAuth2 = google.auth.OAuth2;
而不是var googleAuth = require('google-auth-library');
不要npm install google-auth-library
。如果这样做,请将其从 package.json 中删除并再次执行 npm install
。
确保您拥有最新版本的 googleapis
软件包。如果您不这样做 - 请执行 npm install googleapis@27
以获取它。 (也将其添加到 package.json 以备将来使用)。
对于任何回调 - 而不是 response.items
,请执行 response.data.items
。创建事件时不一定需要回调输出,但列出事件时肯定需要它。所以不要忘记在那里进行更改。
我认为您按照所有这些步骤操作后不会有任何问题。如果还有,就回复这个。我会尽力解决的!
我使用了快速入门中的代码示例,并尝试使用 - https://developers.google.com/calendar/v3/reference/events/insert#examples
上的示例插入事件我检查了网络上可用的资源,其中 none 似乎对我有用(将 googleapis 包降级到版本 24.0.0 或使用不同的方式编写插入事件)。 这是当前addEvents函数的代码-
function addEvents(auth){
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",
},
"recurrence": [
"RRULE:FREQ=DAILY;COUNT=2"
],
"reminders": {
"useDefault": false,
"overrides": [
{"method": "email", "minutes": 24 * 60},
{"method": "popup", "minutes": 10},
],
},
};
//console.log(event)
var calendar = google.calendar("v3");
calendar.events.insert({
auth: auth,
calendarId: "primary",
resource: event,
}, function(err, event) {
if (err) {
console.log("There was an error contacting the Calendar service: " + err);
return;
}
console.log("Event created: %s", event.htmlLink);
});
}
和listEvents函数在同一行-
function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
auth: auth,
calendarId: 'primary',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime'
},
function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var events = response.items;
if (events.length == 0) {
console.log('No upcoming events found.');
}
else {
console.log('Upcoming 10 events:');
for (var i = 0; i < events.length; i++) {
var event = events[i];
var start = event.start.dateTime || event.start.date;
console.log('%s - %s', start, event.summary);
}
}
});
}
谁能帮我解决这个问题?
谢谢!
这些是解决问题所需要做的事情 -
var {google} = require('googleapis');
而不是var google = require('googleapis');
写
var OAuth2 = google.auth.OAuth2;
而不是var googleAuth = require('google-auth-library');
不要
npm install google-auth-library
。如果这样做,请将其从 package.json 中删除并再次执行npm install
。确保您拥有最新版本的
googleapis
软件包。如果您不这样做 - 请执行npm install googleapis@27
以获取它。 (也将其添加到 package.json 以备将来使用)。对于任何回调 - 而不是
response.items
,请执行response.data.items
。创建事件时不一定需要回调输出,但列出事件时肯定需要它。所以不要忘记在那里进行更改。
我认为您按照所有这些步骤操作后不会有任何问题。如果还有,就回复这个。我会尽力解决的!