admin管理员组文章数量:1278720
Google has no documentation for how to remove an event in node.JS
I have been able to add new events to my calendar using the following code:
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);
});
I have been fiddling around with this for 4 hours now, and am looking for a solution.
Google has no documentation for how to remove an event in node.JS
I have been able to add new events to my calendar using the following code:
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);
});
I have been fiddling around with this for 4 hours now, and am looking for a solution.
Share Improve this question asked Apr 30, 2016 at 23:39 Joachim VelzelJoachim Velzel 6562 gold badges9 silver badges23 bronze badges3 Answers
Reset to default 6I hope it helps someone with the same problem/question.
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');
}
});
});
}
To delete an event just call the delete method. The following code can be found on the Node.js GitHub repo for the Google API
delete: function (params, callback) {
var parameters = {
options: {
url: 'https://www.googleapis./calendar/v3/users/me/calendarList/{calendarId}',
method: 'DELETE'
},
params: params,
requiredParams: ['calendarId'],
pathParams: ['calendarId'],
context: self
};
return createAPIRequest(parameters, callback);
}
From : https://github./google/google-api-nodejs-client/blob/b08ce4189e6b2efdc7cf3e7c3bdb3cbabb08da8c/apis/calendar/v3.js
If you wanted it as a function:
First get the eventId of the event you want to delete then call the method below with that 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.');
});
}
below code work for me to delete event from google calendar from 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.
});
本文标签: javascriptDeleting events in Google Calander APIStack Overflow
版权声明:本文标题:javascript - Deleting events in Google Calander API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741300616a2371069.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论