How to update an event in Google Calendar using javascript?

前端 未结 4 1269
萌比男神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:30

            /**
             *  Update an event
             */
            function updateEvent(eventId) {
                if (eventId) {  
                    var eventToUpdate = gapi.client.calendar.events.get({
                        "calendarId": 'primary', 
                        "eventId": eventId
                    });
    
                    eventToUpdate.summary = $("#update-name").val(); //Replace with your values of course :)
                    eventToUpdate.location = $("#update-location").val();
                    eventToUpdate.description = $("#update-description").val();
                    eventToUpdate.start = {
                        'dateTime': (new Date(2017, 04, 22, 8, 00, 00)).toISOString(), //2017-04-22 08h00m00s
                        'timeZone': 'Europe/Paris'
                    };
                    eventToUpdate.end = {
                        'dateTime': (new Date(2017, 04, 22, 9, 00, 00)).toISOString(), //2017-04-22 09h00m00s
                        'timeZone': 'Europe/Paris'
                    };
    
                    var request = gapi.client.calendar.events.patch({
                        'calendarId': 'primary',
                        'eventId':eventId,
                        'resource': eventToUpdate
                    });
    
                    request.execute(function(event) {
                        console.log('Event updated: ' + event.htmlLink);
    
                        //Action. Maybe refresh your events list ? :)
                    });
                }
            }
    

提交回复
热议问题