Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript更新Google日历中的事件?_Javascript_Google Calendar Api - Fatal编程技术网

如何使用javascript更新Google日历中的事件?

如何使用javascript更新Google日历中的事件?,javascript,google-calendar-api,Javascript,Google Calendar Api,一旦我通过JavaScript获得一些Google日历事件,我需要更新它们的名称。我只有谷歌在他们的谷歌开发者网站上展示的示例代码,我找不到谷歌日历API方法列表来在JavaScript中使用它们。我只在API引用中看到REST请求。对不起,我的英语,谢谢。您必须执行HTTP(PUT)请求。这可以通过AJAX或jQuery.AJAX()实现: : 记得实施 我希望这对你有用 嗨,我知道已经很晚了,但我面临着同样的问题,我找到了一个解决方案,所以我认为分享它会很好。 首先,我创建了事件对象,然后将

一旦我通过JavaScript获得一些Google日历事件,我需要更新它们的名称。我只有谷歌在他们的谷歌开发者网站上展示的示例代码,我找不到谷歌日历API方法列表来在JavaScript中使用它们。我只在API引用中看到REST请求。对不起,我的英语,谢谢。

您必须执行HTTP(PUT)请求。这可以通过AJAX或jQuery.AJAX()实现:

:

记得实施


我希望这对你有用

嗨,我知道已经很晚了,但我面临着同样的问题,我找到了一个解决方案,所以我认为分享它会很好。 首先,我创建了事件对象,然后将动态值传递给对象键

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}
    ]
  }
};  
我在数据库中存储了一个google事件id

var google_event_id = '728326gghd';
然后我将id变量和事件对象传递给GoogleCalendarAPI更新方法

  var request = gapi.client.calendar.events.update({
                  'calendarId': 'primary',
                  'eventId':google_event_id,
                  'resource': event
                });
然后我执行请求

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

在被问到这个问题5年多之后,我是如何成功的:

/**
 * changes transparency (i.e. Busy or Available) of event passed
 * 
 * @author dugBarnz
 * @version 1.0
 * @since 2021/01/11
 * @param {string} event id
 */
function zzChangeTransparency_(_calendarId, _eventId)
{
  var event = Calendar.Events.get(_calendarId, _eventId);
  if (event && event.transparency)
    event.transparency = "opaque";
  else
    event.transparency = "transparent";

  Calendar.Events.update(event, _calendarId, _eventId);
}
        /**
         *  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 ? :)
                });
            }
        }
/**
 * changes transparency (i.e. Busy or Available) of event passed
 * 
 * @author dugBarnz
 * @version 1.0
 * @since 2021/01/11
 * @param {string} event id
 */
function zzChangeTransparency_(_calendarId, _eventId)
{
  var event = Calendar.Events.get(_calendarId, _eventId);
  if (event && event.transparency)
    event.transparency = "opaque";
  else
    event.transparency = "transparent";

  Calendar.Events.update(event, _calendarId, _eventId);
}