How to update an event in Google Calendar using javascript?

前端 未结 4 1307
萌比男神i
萌比男神i 2021-01-17 04:49

I need to update the name of some Google Calendar events, once I get them through JavaScript. I only have the sample code which Google shows in their Google Developer site,

4条回答
  •  情歌与酒
    2021-01-17 05:29

    Hi I know it's late but i face the same issue i found a solution so i thought sharing it will be good. First i created the event object then pass the dynamic values to object keys

    var event = {
      'summary': summaryTxt,
      'location': locationTxt,
      'description': ' ',
      'start': {
        'dateTime': datetime,
      },
      'end': {
        'dateTime': datimeEnd,
      },
    
    
      'reminders': {
        'useDefault': false,
        'overrides': [
          {'method': 'email', 'minutes': 24 * 60},
          {'method': 'popup', 'minutes': 10}
        ]
      }
    };  
    

    I have a google event id stored in database

    var google_event_id = '728326gghd';
    

    Then i pass the id variable and event object to Google Calendar Api update method

      var request = gapi.client.calendar.events.update({
                      'calendarId': 'primary',
                      'eventId':google_event_id,
                      'resource': event
                    });
    

    Then i execute the request

     request.execute(function(event) {
                        alert('Event updated successfully' );
                    });
    

提交回复
热议问题