我已将我的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。 No' 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', '*');
答案 0 :(得分:0)
我已设法通过使用此方法将ICS
文件转到fullcalendar -
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;
}