从 'ics' 文件接收 Google 日历事件并将其与 FullCalendar 一起使用

Receive Google Calender events from 'ics' file and use it with FullCalendar

我已将我的 google 日历放在 public 中,我正在尝试使用 ics 文件,但 XMLHttpRequest

到目前为止我尝试过的:

如果我使用我的 googleCalendarId 和 googleCalendarApiKey:

它会起作用
   $('#calendar').fullCalendar({
        googleCalendarApiKey: '*************myApiKey**************',

        events: {
          googleCalendarId: 'chris.beckett@schoolspider.co.uk'
        },

        eventClick: function(event) {
            console.log(event.start);
            console.log(event.end);
            return false;
        }, 

        loading: function(bool) {
            $('#loading').toggle(bool);
        }
    });

然后当我尝试像这样使用实际的 ics 文件时:

   $('#calendar').fullCalendar({        
        events: {
          url: 'https://calendar.google.com/calendar/ical/chris.beckett%40schoolspider.co.uk/public/basic.ics'
        },

        eventClick: function(event) {
            console.log(event.start);
            console.log(event.end);
            return false;
        }, 

        loading: function(bool) {
            $('#loading').toggle(bool);
        }
    });

它在控制台日志中显示以下错误:

XMLHttpRequest cannot load https://calendar.google.com/calendar/ical/chris.beckett%40schoolspider.co.uk/public/basic.ics. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8887' is therefore not allowed access.

我也试过设置以下内容:

//htaccess file
Header set Access-Control-Allow-Origin "*"
//php 
header("Access-Control-Allow-Origin: *");
//xhr 
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');

我已经使用此方法将 ICS 文件添加到完整日历 -

function icsToArray($paramUrl) {
        $icsFile = file_get_contents($paramUrl);

        $icsData = explode("BEGIN:", $icsFile);

        foreach($icsData as $key => $value) {
            $icsDatesMeta[$key] = explode("\n", $value);
        }

        foreach($icsDatesMeta as $key => $value) {
            foreach($value as $subKey => $subValue) {
                if ($subValue != "") {
                    if ($key != 0 && $subKey == 0) {
                        $icsDates[$key]["BEGIN"] = $subValue;
                    } else {
                        $subValueArr = explode(":", $subValue, 2);
                        $icsDates[$key][$subValueArr[0]] = $subValueArr[1];
                    }
                }
            }
        }
        return $icsDates;
    }