要删除事件,只需调用delete方法。以下代码可以在Google API 的Node.js GitHub repo上找到
Google没有关于如何删除节点中事件的文档。JS-
我已经能够使用以下代码将新事件添加到我的日历中:
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);
});
我已经花了4个小时来处理这个问题,正在寻找解决方案。
delete: function (params, callback) {
var parameters = {
options: {
url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList/{calendarId}',
method: 'DELETE'
},
params: params,
requiredParams: ['calendarId'],
pathParams: ['calendarId'],
context: self
};
return createAPIRequest(parameters, callback);
}
发件人:https://github.com/google/google-api-nodejs-client/blob/b08ce4189e6b2efdc7cf3e7c3bdb3cbabb08da8c/apis/calendar/v3.js
如果您想将其作为一个函数:
首先获取要删除的事件的eventId,然后使用该eventId 调用下面的方法
function deleteEvent(eventId) {
var params = {
calendarId: 'primary',
eventId: eventId,
};
calendar.events.delete(params, function(err) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
console.log('Event deleted.');
});
}
我希望它能帮助有同样问题的人。
function deleteEvent(event_id) {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.delete({
'calendarId': 'xxxxxxxxxxxxxxx',
'eventId': event_id
});
request.execute(function(response) {
if(response.error || response == false){
alert('Error');
}
else{
alert('Success');
}
});
});
}
下面的代码帮助我从nodejs中删除谷歌日历中的事件。
const {google} = require("googleapis")
const oauth2client = new google.auth.OAuth2(
google_client_id,
google_client_secret,
redirect_url // for ex. http://localhost:3000
)
const calendar = google.calendar("v3");
oauth2client.setCredentials({refresh_token:user_refresh_token})
//you can access user refresh token while he logged in first time using google
await calendar.events.delete({
auth: oauth2client,
calendarId: 'primary',
eventId: eventId //eventId you will get while creating event.
});