Fullcalander.js使用google a.p.i日历删除事件

时间:2019-05-13 11:23:51

标签: javascript php laravel fullcalendar google-calendar-api

我正在使用FullCalendar库从Google日历加载日历中的事件。日历确实显示事件,但是现在我希望能够删除/删除与Google日历同步的事件。我现在正在寻找如何做的几天,但找不到答案。

(我知道有几个人遇到同样的问题,但对我来说不起作用) 我希望有人能帮助我找到解决方案。

document.addEventListener('DOMContentLoaded', function() {
                var calendarEl = document.getElementById('calendar');

                var calendar = new FullCalendar.Calendar(calendarEl, {
                    plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list', 'bootstrap', 'googleCalendar'],
                    customButtons: {
                        myCustomButton: {
                            text: 'custom!',
                            click: function() {
                                alert('clicked the custom button!');
                            }
                        }
                    },
                    header: {  right:  'prev,next today,list,dayGridDay,timeGridWeek,dayGridMonth', left: 'prev,next today myCustomButton' }, // buttons for switching between views
                    defaultView: 'timeGridWeek',
                    themeSystem: 'bootstrap',
                    editable: true,
                    eventLimit: true,
                    eventRender: function(eventObj, el) {

                    },
                    // Showing events
                    events:  {!! json_encode($events) !!},
                });

                calendar.render();
            });

这是我加载事件的方式:

$request->validate([ 'calendar_id' => 'required', ]); 
$gclient = new Gclient; $client = $gclient->client(); 
$cal = Calendar::find($request['calendar_id']); 
$client->setAccessToken($cal->gmail->token); 
$gcal_id = isset($cal->calendar_id) ? $cal->calendar_id : env('GOOGLE_DEFAULT'); 
$g_cal = new \Google_Service_Calendar($client); 
$eventlist = $g_cal->events->listEvents($gcal_id)->getItems();
$events = []; 

foreach ($eventlist as $event) { 
  if ($event->summary == NULL ) { 
    if ($event->location == NULL ) {
      $title = 'default';
    }
    else { 
      $title = $event->location; 
    } 
  }
  else { 
    $title = $event->summary; 
  }

  $events[] = [ 
    'title' => $title, 
    'start' => $event->start->dateTime, 
    'end' => $event->end->dateTime, 
    'id' => $event->id 
  ]; 
}

0 个答案:

没有答案