【问题标题】:Receive Google Calender events from 'ics' file and use it with FullCalendar从“ics”文件接收 Google 日历事件并将其与 FullCalendar 一起使用
【发布时间】:2016-03-10 15:14:17
【问题描述】:

我已经公开了我的谷歌日历,我正在尝试使用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 无法加载 https://calendar.google.com/calendar/ical/chris.beckett%40schoolspider.co.uk/public/basic.ics。 请求中不存在“Access-Control-Allow-Origin”标头 资源。因此不允许使用原点“http://127.0.0.1:8887” 访问。

我也尝试过以下设置:

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

【问题讨论】:

标签: javascript fullcalendar google-calendar-api icalendar gcal


【解决方案1】:

我已经设法通过使用这种方法将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;
    }

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 2020-09-08
    • 2016-12-27
    • 2015-07-05
    • 2015-02-14
    • 2018-10-29
    • 2019-08-03
    • 2019-01-21
    • 1970-01-01
    相关资源
    最近更新 更多