I have been trying to create a .ics page in php which is to be added to Google Calendar via "Add by URL" in order for me to retrieve events from a database and present them in the calendar.
I have searched around a while on SO and found another post which was very helpful in getting started, but I have now hit a snag which doesn't seem to affect those with similar code. Post can be found here.
So, my problem is that I cannot seem to get the Google Calendar to update my page, as if it has cached the page within the calendar. So when I add another VEVENT to the page it does not update the calendar.
When creating the file it generates the correct format for an *.ics file. Format shown below.
If I go directly to the page I do get prompted to download the file, which works to import into GC, and if I add the same code to a different page, for instance changing the pages name from cal.php to cal2.php, will make GC read all of the events whilst when I simply add the same URL as before it does not pick up on any changes made to the file.
Anyone have any idea to why this isn't updating?
Others who have had similar problems have solved this by adding a UID to their VEVENT, which did not solve this anything for me...
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20110901T092002Z
DTSTART:20110925T170000Z
DTEND:20110928T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20110901T092002Z
DTSTART:20110929T170000Z
DTEND:20110930T035959Z
SUMMARY:Camping Trip
END:VEVENT
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20110901T092002Z
DTSTART:20110914T170000Z
DTEND:20110915T035959Z
SUMMARY:Testing new Event
END:VEVENT
END:VCALENDAR
<?php
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=\"calendar.ics\"");
echo "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20110925T170000Z
DTEND:20110928T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20110929T170000Z
DTEND:20110930T035959Z
SUMMARY:Camping Trip
END:VEVENT
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20110914T170000Z
DTEND:20110915T035959Z
SUMMARY:Testing new Event
END:VEVENT
END:VCALENDAR";
?>
ics file, you get a snapshot of the events in the calendar at the time of import. Your calendar doesn't refresh the imported events automatically -- even if the calendar's owner makes an update.
csanyigabor is correct. Also you must ensure that the UID's are the same so that the application will match the events. This question and answer here deals with cancelations, but the principle is the same How to cancel an calendar event using ics files?
I think you should use the SEQUENCE attribute in VEVENT and it should increases after every change.
@csanyigabor is right and so is @anmari, but a few other tips I picked up. When you are building your ICS file, like anmari said, make sure your UID's are consistent every time your feed is sync'd. I had made it create a hash based on some text provided by the user (bad, bad idea. Shame on myself 5 years ago when I built it).
If you go here -> https://www.rfc-editor.org/rfc/rfc5545 (and a few updated points here -> https://www.rfc-editor.org/rfc/rfc7986 ) it gives some great outlines on stuff that's helpful. Specifically 3.8.7.4. Sequence Number
and it outlines what should be criteria for a new sequence.
Description: When a calendar component is created, its sequence
number is 0. It is monotonically incremented by the "Organizer's"
CUA each time the "Organizer" makes a significant revision to the
calendar component.
Also helpful is what it says about UID in 3.8.4.7. Unique Identifier
Description: The "UID" itself MUST be a globally unique identifier.
The generator of the identifier MUST guarantee that the identifier
is unique. There are several algorithms that can be used to
accomplish this. A good method to assure uniqueness is to put the
domain name or a domain literal IP address of the host on which
the identifier was created on the right-hand side of an "@", and
on the left-hand side, put a combination of the current calendar
date and time of day (i.e., formatted in as a DATE-TIME value)
along with some other currently unique (perhaps sequential)
identifier available on the system (for example, a process id
number). Using a DATE-TIME value on the left-hand side and a
domain name or domain literal on the right-hand side makes it
possible to guarantee uniqueness since no two hosts should be
using the same domain name or IP address at the same time. Though
other algorithms will work, it is RECOMMENDED that the right-hand
side contain some domain identifier (either of the host itself or
otherwise) such that the generator of the message identifier can
guarantee the uniqueness of the left-hand side within the scope of
that domain.
Example: The following is an example of this property:
UID:[email protected]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With