2015-10-19 21 views
10

Utworzono plik kalendarza (.ics) z mojej aplikacji do celów konsumpcyjnych w aplikacji Kalendarz, takiej jak Kalendarz Google. Uruchomiłem poniższy plik za pomocą walidatora, ale wygląda na to, że ani Google, ani Yahoo Calendars nie chcą grać w piłkę. Klient Mój lokalny kalendarz Mac działa w 100%. Czy ktoś może zobaczyć cokolwiek oczywistego na temat poniższego pliku, który potencjalnie mógłby się dusić w Kalendarzu Google? Lub dodatkowe pola, których potrzebują? Dostaję 500 błędów z kalendarza Yahoo. W tym momencie rozdzierają włosy.Format iCal dla Kalendarza Google/kalendarza Yahoo nie działa

Próbowałem z i bez informacji strefy czasowej, i nie wydaje się, że robi dużą różnicę.

wyjściowe Header

 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); 
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
     header('Cache-Control: no-store, no-cache, must-revalidate'); 
     header('Cache-Control: post-check=0, pre-check=0', false); 
     header('Pragma: no-cache'); 
     header('Content-type: text/calendar;'); 
     header('Content-Disposition: inline; filename="calendar.ics"'); 
     header("Content-Description: File Transfer"); 
     header("Content-Transfer-Encoding: binary"); 
     header("Content-Length: " . strlen($generated)); 

razy UTC lub TZID Mam eksperymentował ze i nie wydaje się, aby różnica. Jeśli ktoś ma naprawdę prosty przykład adresu URL zdarzeń .ics, który wydaje się działać "w kalendarzu", chciałby go zobaczyć. Ewentualnie, jeśli ktoś może dostarczyć do tego celu przyzwoite biblioteki, które nie są uciążliwe dla integracji z projektem CakePHP, to wystarczy.

BEGIN:VCALENDAR 
VERSION:2.0 
PRODID:-//MS//NONSGML//EN 
X-WR-CALNAME:Holidays 
CALSCALE:GREGORIAN 
METHOD:PUBLISH 
BEGIN:VEVENT 
UID:1075 
DTSTART;TZID=Europe/London:20150114T080000 
DTEND;TZID=Europe/London:20150114T170000 
DTSTAMP:20150114T080000Z 
CREATED:20151019T211433Z 
DESCRIPTION:Stat Holiday (1.0 days) 
LAST-MODIFIED:20150114T080000Z 
LOCATION: 
SUMMARY: Statutory Day 
SEQUENCE:0 
STATUS:CONFIRMED 
TRANSP:OPAQUE 
END:VEVENT 
BEGIN:VEVENT 
UID:1076 
DTSTART;TZID=Europe/London:20150116T080000 
DTEND;TZID=Europe/London:20150116T170000 
DTSTAMP:20150116T080000Z 
CREATED:20151019T211433Z 
DESCRIPTION:Stat Holiday (1.0 days) 
LAST-MODIFIED:20150116T080000Z 
LOCATION: 
SUMMARY: Statutory Day 
SEQUENCE:0 
STATUS:CONFIRMED 
TRANSP:OPAQUE 
END:VEVENT 
BEGIN:VEVENT 
UID:1079 
DTSTART;TZID=Europe/London:20151020T123000 
DTEND;TZID=Europe/London:20151020T170000 
DTSTAMP:20151020T123000Z 
CREATED:20151019T211433Z 
DESCRIPTION:Holiday Request (3.0 days) test 
LAST-MODIFIED:20151020T123000Z 
LOCATION: 
SUMMARY:admin Leave 
SEQUENCE:0 
STATUS:CONFIRMED 
TRANSP:OPAQUE 
END:VEVENT 
BEGIN:VEVENT 
UID:1080 
DTSTART;TZID=Europe/London:20151021T080000 
DTEND;TZID=Europe/London:20151021T123000 
DTSTAMP:20151021T080000Z 
CREATED:20151019T211433Z 
DESCRIPTION:Holiday (3.0 days) test 
LAST-MODIFIED:20151021T080000Z 
LOCATION: 
SUMMARY:admin Leave 
SEQUENCE:0 
STATUS:CONFIRMED 
TRANSP:OPAQUE 
END:VEVENT 
BEGIN:VEVENT 
UID:1081 
DTSTART;TZID=Europe/London:20151022T080000 
DTEND;TZID=Europe/London:20151022T170000 
DTSTAMP:20151022T080000Z 
CREATED:20151019T211433Z 
DESCRIPTION:Holiday Request (3.0 days) test 
LAST-MODIFIED:20151022T080000Z 
LOCATION: 
SUMMARY:admin Leave 
SEQUENCE:0 
STATUS:CONFIRMED 
TRANSP:OPAQUE 
END:VEVENT 
BEGIN:VEVENT 
UID:1082 
DTSTART;TZID=Europe/London:20151023T080000 
DTEND;TZID=Europe/London:20151023T170000 
DTSTAMP:20151023T080000Z 
CREATED:20151019T211433Z 
DESCRIPTION:Holiday Request (3.0 days) test 
LAST-MODIFIED:20151023T080000Z 
LOCATION: 
SUMMARY:admin Leave 
SEQUENCE:0 
STATUS:CONFIRMED 
TRANSP:OPAQUE 
END:VEVENT 
END:VCALENDAR 
+1

Jak ty wyprowadzania pliku ICS z php, poprzez echa? Mogę zaimportować twój kalendarz prosto do kalendarza Google, więc plik jest w porządku. –

+0

Nie wiem _how_ próbujesz załadować to, ale używając tylko nagłówków HTTP i podanego pliku .ics, udało mi się [_Dodać za pomocą linku_] (https://support.google.com/ calendar/answer/37100? hl = en) bez problemów. – HPierce

Odpowiedz

4

Za pomocą kombinacji odpowiedzi na SO (Google Calendar errors on importing .ics file), a niektóre kod źródłowy z https://gist.github.com/jakebellacera/635416

mojego kodu roboczego przetestowany w kilku narzędzi jest:

<?php 

//test 
// 
$summary = "test"; 
$datestart=time(); 
$dateend = $datestart + 3600; 
$address = "Amsterdam"; 
$description = "testing ical format"; 
$filename = "test.ics"; 

// Variables used in this script: 
// $summary  - text title of the event 
// $datestart - the starting date (in seconds since unix epoch) 
// $dateend  - the ending date (in seconds since unix epoch) 
// $address  - the event's address 
// $uri   - the URL of the event (add http://) 
// $description - text description of the event 
// $filename - the name of this file for saving (e.g. my-event-name.ics) 
// 
// Notes: 
// - the UID should be unique to the event, so in this case I'm just using 
// uniqid to create a uid, but you could do whatever you'd like. 
// 
// - iCal requires a date format of "yyyymmddThhiissZ". The "T" and "Z" 
// characters are not placeholders, just plain ol' characters. The "T" 
// character acts as a delimeter between the date (yyyymmdd) and the time 
// (hhiiss), and the "Z" states that the date is in UTC time. Note that if 
// you don't want to use UTC time, you must prepend your date-time values 
// with a TZID property. See RFC 5545 section 3.3.5 
// 
// - The Content-Disposition: attachment; header tells the browser to save/open 
// the file. The filename param sets the name of the file, so you could set 
// it as "my-event-name.ics" or something similar. 
// 
// - Read up on RFC 5545, the iCalendar specification. There is a lot of helpful 
// info in there, such as formatting rules. There are also many more options 
// to set, including alarms, invitees, busy status, etc. 
// 
//  https://www.ietf.org/rfc/rfc5545.txt 
// 1. Set the correct headers for this file 
header('Content-type: text/calendar; charset=utf-8'); 
header("Content-Disposition:inline;filename=".$filename); 
// 2. Define helper functions 
// Converts a unix timestamp to an ics-friendly format 
// NOTE: "Z" means that this timestamp is a UTC timestamp. If you need 
// to set a locale, remove the "\Z" and modify DTEND, DTSTAMP and DTSTART 
// with TZID properties (see RFC 5545 section 3.3.5 for info) 
// 
// Also note that we are using "H" instead of "g" because iCalendar's Time format 
// requires 24-hour time (see RFC 5545 section 3.3.12 for info). 
function dateToCal($timestamp) { 
    return date('Ymd\THis\Z', $timestamp); 
} 
// Escapes a string of characters 
function escapeString($string) { 
    return preg_replace('/([\,;])/','\\\$1', $string); 
} 
// 3. Echo out the ics file's contents 
$iCal="BEGIN:VCALENDAR\r 
VERSION:2.0\r 
PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r 
CALSCALE:GREGORIAN\r 
BEGIN:VEVENT\r 
DTSTAMP:".dateToCal(time())."\r 
DTSTART:".dateToCal($datestart)."\r 
DTEND:".dateToCal($dateend)."\r 
UID:".uniqid()."\r 
LOCATION:".escapeString($address)."\r 
DESCRIPTION:".escapeString($description)."\r 
SUMMARY:".escapeString($summary)."\r 
END:VEVENT\r 
END:VCALENDAR"; 
file_put_contents($filename,$iCal); 
print file_get_contents($filename); 
unlink($filename); 
exit; 
?> 

Wydaje się ważne, że zakończeń linii są poprawne (tak \ r \ n).

+0

Działa to w kalendarzach Mac/Google. Kalendarz Yahoo wciąż borks. – Paul

4

Twój plik jest poprawny, mam wysłał go do kalendarzami Google siebie, więc powinien działać, jednak jeśli nie zatrzymując skrypt po echo plików, na przykład:

//somewhere else in the script 
    echo "this will break the file"; 
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); 
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
    header('Cache-Control: no-store, no-cache, must-revalidate'); 
    header('Cache-Control: post-check=0, pre-check=0', false); 
    header('Pragma: no-cache'); 
    header('Content-type: text/calendar;'); 
    header('Content-Disposition: inline; filename="calendar.ics"'); 
    header("Content-Description: File Transfer"); 
    header("Content-Transfer-Encoding: binary"); 
    header("Content-Length: " . strlen($generated)); 
    echo $generated; 
    exit;//or return 200 or whatever 
    echo "this could break the file except there is an exit;";//for example. 

Można być w istocie wysyłając zniekształcony plik.

+0

dobre miejsce, jak o ':: foobar ::' lub ';; foobar ;;' .. lub ewentualnie ten sam plik ponownie? –

+1

Interesujące - z jakiegokolwiek powodu, cokolwiek dodam: "echo" foobar ";" lub "echo" :: foobar :: ";" nawet nie pojawia się w dostarczonym pliku wyjściowym. _ ** ale ** _ usuwanie rzeczy z '$ generated' faktycznie usuwa je z danych wyjściowych. Nie mam pojęcia, co mam myśleć. (nie używam twojego przykładu wyjścia po wygenerowaniu '$ generated') – HPierce

+1

zobacz moją edycję, testowałem to, to ją zepsuje. –

0

W .ics pliku dodałem jedną linię

METHOD:REQUEST 

i Yahoo rozpoczął pracę. W moim przypadku wysłałem maile do hotmail, gmail i yahoo z plikiem .ics, a Yahoo nie działało bez tej linii. Z

METHOD:PUBLISH 

yahoo również dosn't praca

Powiązane problemy