Exposing calendar as an iCal with subscribe option in PHP
Asked Answered
A

2

8

I have an application in PHP where each user has his associated events.

What I want to do is to expose his events under in a way similar to events on facebook which gives urls in format webcal://www.facebook.com/ical/b.php?uid=123456789&key=ASD123ASD123ASD and whenever there's a new event, it automatically gets propagated to my calendar which I have added to my google calendar.

What I want to do is expose this calendar on a url such as http://whatever.org/someLongUniquePerUserIdentifier.ics.

I tried to simulate the event generation script with a simple file that was at the same url. It was an ics file that was consumed by google, the events have been added, but when I changed the file contents (deleted an event) = altered the resource, to which google calendar should be subscribed, the change simply didn't go through to gcal.

As I was unable to find any reliable source of documentation, I tried to google a lot with different keywords and I was only guided to webdav servers like DAVical, sabredav, etc.

I have installed DAVical on my server only to getting to a state where I have the server properly installed but no idea how to expose the events from my MySQL database on my desired url, which would the clients subscribe to.

Same with sabredav, except for the fact, that I haven't tried getting it to work, because I can't see any documented way of getting my events out to the world using any of the dav server.

I am basically stuck in a place where I have working ics export in PHP which is not getting asked for updates by calendar clients, and a running CalDAV server which might be asked by clients for updates, but has no data to return.

Any thoughts?

EDITED QUESTION:

What is the right way to achieve instant one-way calendar sync?

Arielle answered 21/4, 2014 at 22:1 Comment(2)
Note: It may take up to 8 hours for changes in ICS feeds to reflect in your Google Calendar.Biosynthesis
@Biosynthesis integrated it in my answer. OP doesn't believe its done through polling at an interval.Louls
W
9

If I am not mistaken, it seems that you simply need to change your link from http://whatever.org/someLongUniquePerUserIdentifier.ics to webcal://whatever.org/someLongUniquePerUserIdentifier.ics

The webcal protocol is supposed to trigger the "subscribe" action in your calendar software. If you are seeing it download a file then it's not subscribing.

Waxwing answered 28/4, 2014 at 4:16 Comment(3)
From what I've googled I am convinced I need to have some CalDAV server in order for the synchronization to work. Simply changing the scheme didn't work, it was one of the first things I've tried.Arielle
I've definitely gotten the sync to work without a CalDAV server. I'm simply generating a .ics file and using webcal:// to link to it. When the link is clicked, the iCal app opens up and has the subscribe dialog open rather than the import dialog (which is what it has when I use http://). When you manually subscribe to your .ics URL in your calendar app, does it work then?Waxwing
@Arielle You only have to run CalDAV if you want 2 way sync... CalDAV is to webcal as WebDAV is to rssfeed. You really don't need the DAV extensions if you don't want your clients to write to your server.Louls
L
6

The .ics format is defined in RFCs 5545 and 6868. You could implement your output yourself. But as it contains tricky bits like UTC datetimes, you might be more robust when using a library.

Subscription to your events is nothing but adding your url to a calendar app, which will poll it for changes. Removing an event might not remove it from the calendar, changing its status to CANCELLED, should.

I have no experience with any PHP library for the format, but googling for it will get you lots. It looks like the Drupal project is discussing it and is trying iCalcreator.


If you don't believe me:

Outlook

Add an Internet Calendar Subscription to Outlook An Internet Calendar Subscription is a calendar that you download and view in Outlook. However, unlike a Calendar Snapshot, Internet Calendar Subscriptions are updated automatically.

These calendars can be found on Web sites where people host calendars. On such a Web site, you can click a link to download and subscribe to the calendar, or someone can send you a link to the Internet Calendar Subscription in an e-mail message. This link is an Internet Web address that begins with webcal://, instead of http://, and ends with a file name that has the .ics file extension.

Google Calendar

Select Add by URL from the menu. Find the address of the Google Calendar in iCalendar format, or if you have the iCalendar address of a calendar from a different application (for example, Apple's iCal), you can use this as well. Enter the address in the field provided.

[...]

Note: It may take up to 8 hours for changes in ICS feeds to reflect in your Google Calendar

It has been that way since

Wayback

[...]You should also treat this calendar as something that should be periodically checked for changes and not a calendar that is imported one time. Simple, but effective.

So if it really isnt the case,where you just add url to your the ics resource to your calendar and it will automatically update, then perhaps that's related to the fact that the webcal uri-scheme is unofficial and the IANA document is full of unknowns.


If you just want one way synchronisation, then you don't need a DAV server. You'll only need a CalDAV server for 2 way synch; if you want clients to update the calendar on your server too.

Louls answered 24/4, 2014 at 13:42 Comment(8)
Thanks for your answer, but it really isnt the case, where you just add url to your the ics resource to your calendar and it will automatically update. I've tried exposing the ICS file and modifying it (as stated above) without the changed being propagated to the calendar. I also have no problem generating the iCal, which I have also stated in the question.Arielle
thanks for your update. The thing is, that "It may take up to 8 hours", which made me think the changes are not propagated at all. But what about the case where you want instant one-way sync?Arielle
@elwhis most clients have a refresh function, don't know if Google provides one.Louls
So there is no way to achieve instant event propagation? Such that when I create and event in my app, it gets instantly pushed to calendar clients?Arielle
@elwhis sure, you could start standardisation. Then be an advocate for adoption, then hope your userbase updates its clients. But why do you need instant updates? You only need your users to be updated in time for the next eventLouls
I need it because it's not an event planning app, it's your work calendar, which you need up-to-date all the time, not tomorrowArielle
First of all, +1. Second of all, applying STATUS => CANCELLED adds a strikethrough effect in iCalendar. Is it possible to completely remove VEVENTs?Oared
@NinoŠkopac First of all, sounds like a question, not a comment. ;-) Second of all: stackoverflow.com/a/17979482Louls

© 2022 - 2024 — McMap. All rights reserved.