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 badges
Add a ment  | 

3 Answers 3

Reset to default 6

I 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