PHP为Google日历生成日历Feed

时间:2018-01-03 12:57:22

标签: php calendar google-calendar-api icalendar

我无法为Google日历生成日历Feed。这适用于Office 365(甚至在数据库中更改时更新事件),但我无法使其与Google一起使用。

当我尝试将网址导入谷歌时,没有任何反应,似乎它被卡住了。如果我重新加载日历页面,我会看到添加了日历,但根本没有任何事件。

header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');

define('DATE_ICAL', 'Ymd\THis\Z');

$eol = "\r\n";

$output = 
"BEGIN:VCALENDAR" . $eol .
"VERSION:2.0" . $eol .
"PRODID:-//CALENDAR//EVENTS//EN" . $eol .
"CALSCALE:GREGORIAN" . $eol;

// loop over events
foreach ($mysqli->query("SELECT * FROM events WHERE active = 1") as $appointment):
    $output .=
    "BEGIN:VEVENT" . $eol .
    "SUMMARY:$appointment[name]" . $eol .
    "UID:$appointment[event_id]" . $eol .
    "STATUS:CONFIRMED" . $eol .
    "DTSTART:" . date(DATE_ICAL, strtotime($appointment[since])) . $eol .
    "DTEND:" . date(DATE_ICAL, strtotime($appointment[till])) . $eol .
    "LAST-MODIFIED:" . date(DATE_ICAL, strtotime($appointment[modifiedon])) . $eol .
    "DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z" . $eol .
    "LOCATION:$appointment[place]" . $eol .
    "GEO:" . str_replace(' ','',str_replace(',',';',$appointment[gps])) . $eol .
    "SEQUENCE:$appointment[sequence]" . $eol .
    "URL:$appointment[fb_link]" . $eol .
    "END:VEVENT" . $eol;
endforeach;

//"DESCRIPTION:" . strip_tags($appointment[sop]) . $eol .

$output .= "END:VCALENDAR";

输出就是这样:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDAR//EVENTS//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Some event
UID:1
STATUS:CONFIRMED
DTSTART:20170811T180000Z
DTEND:20170812T030000Z
LAST-MODIFIED:20171206T125444Z
DTSTAMP:20180103T124514Z
LOCATION:Some address
GEO:58.049040;17.214640
SEQUENCE:1
URL:
END:VEVENT
END:VCALENDAR

有什么想法吗?感谢。

0 个答案:

没有答案