2015-10-19 18 views
10

Ho creato un file di calendario (.ics) in uscita dalla mia applicazione a scopo di consumo all'interno di un'app Calendar come Google Calendar. Ho eseguito il file seguente tramite un validatore, ma sembra che né Google né i calendari di Yahoo vogliano giocare a pallone. Il mio client Calendar Mac locale funziona al 100%. Qualcuno può vedere qualcosa di ovvio sul file qui sotto che potrebbe soffocare in Google Calendar? O altri campi aggiuntivi di cui hanno bisogno? Ricevo anche un errore di 500 dal calendario di Yahoo. Strappare i capelli a questo punto.Formato iCal per Google Calendar/Calendario Yahoo non funzionante

Ho provato con e senza informazioni sul fuso orario e non sembra fare molta differenza.

uscita 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)); 

volte UTC o TZID Ho sperimentato e non sembra fare la differenza. Se qualcuno ha un semplice esempio di URL di eventi .ics che sembra funzionare "cross calendar", mi piacerebbe vederlo. In alternativa, se qualcuno può fornire alcune librerie decenti per questo scopo che non sono un problema da integrare in un progetto CakePHP, sarebbe sufficiente.

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

Come stai emissione del file ICS da PHP, tramite l'eco? Posso importare il tuo calendario direttamente nel calendario di google in modo che il file sia ok. –

+0

Non so _how_ stai provando a caricare questo, ma utilizzando solo le intestazioni HTTP e il file .ics che hai fornito sono riuscito a [_Aggiungere utilizzando un link_] (https://support.google.com/ calendar/answer/37100? hl = en) senza problemi. – HPierce

risposta

4

Usando una combinazione di risposte a SO (Google Calendar errors on importing .ics file) e qualche codice sorgente da https://gist.github.com/jakebellacera/635416

Il mio codice di lavoro testato in diversi strumenti è:

<?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; 
?> 

Mi sembra importante che la fine riga sono corretti (quindi \ r \ n).

+0

Funziona con calendari Mac/Google. Il calendario di Yahoo continua ancora. – Paul

4

Il file è corretto, ho caricato a Google calendari me stesso, così dovrebbe funzionare, se non si sta fermando lo script dopo il file eco, ad esempio:

//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. 

Potresti essere in sostanza, l'invio di un file malformato.

+0

buon posto, che ne dite di ':: foobar ::' o ';; foobar ;;' .. o forse di nuovo lo stesso file? –

+1

Interessante - per qualsiasi ragione, qualunque cosa aggiungo: "echo" foobar ";' or 'echo ":: foobar ::"; 'non appare nemmeno nell'output fornito. _ ** ma ** _ rimuovendo elementi da $ $ generate in realtà li rimuove dall'output. Non ho idea di cosa pensare più. (Non sto usando il tuo esempio di uscita dopo aver emesso '$ generate' o) – HPierce

+1

vedi la mia modifica, è stata testata, l'ha interrotta. –

0

In .ics file aggiunto una riga

METHOD:REQUEST 

e Yahoo ha iniziato a lavorare. Nel mio caso ho inviato mail a hotmail, gmail e yahoo con il file .ics e yahoo non ha funzionato senza quella linea. Con

METHOD:PUBLISH 

yahoo dosn't anche il lavoro

Problemi correlati