0

Googleカレンダーを公開してファイルを使用しようとしてい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', '*');
4

1 に答える 1

0

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;
    }
于 2016-03-16T10:58:17.510 に答える