I am currently looking into the possibility of displaying lists of events from multiple Google Calendars on a Web page. At the moment, I'm using the Google Calendar Events plugin for WordPress to display the events on the site (development site behind a firewall, so I can't share a link); but I'd like to see if there's any simple method to dynamically generate ICS files for each individual event.
We would like to allow the website visitors to add individual events to their calendars, but the Google Calendar Data API only seems to provide the option to download an entire calendar in ICS format. I tried simply appending a query string with the eid (event ID) to the end of the ICAL feed address, but that still opens the standard Google ICAL feed, which includes all of the events currently included on the calendar.
I am somewhat familiar with dynamically building ICS files from scratch, and have done it once in the past, pulling events from a local Perl calendar program and generating an ICS file for each event; but if there are any pre-built APIs or PHP classes that are already set up to build ICS files from individual Google Calendar Events, I'd much prefer to use those.
Its so simple its just a page really, try this: (you'll need to substitute you own variables of course ...)
<?php
/*
* generates calendar ics file
*/
if(
empty($_GET['summary']) ||
empty($_GET['dtstart']) ||
empty($_GET['dtend'])
){
header ("Location: /diary/this-week") ;
exit();
}
header("Content-type: text/calendar");
header("Content-Disposition: attachment; filename=".urlencode($_GET['summary']).'-'.time().".ics");
header("Pragma: no-cache");
header("Expires: 0");
echo 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:councilsites
METHOD:PUBLISH
BEGIN:VEVENT
URL:'. htmlentities( $_GET['url'] ) .'
UID:'. htmlentities( $_GET['url'] ) .'
SUMMARY:'. htmlentities( $_GET['summary'] ) .'
DTSTAMP:'. date('Ymd\THis\Z') .'
DTSTART:'. htmlentities( $_GET['dtstart'] ) .'
DTEND:'. htmlentities( $_GET['dtend'] ) .'
LOCATION:'. htmlentities( $_GET['location'] ) .'
END:VEVENT
END:VCALENDAR';
?>
Some PHP Libraries I was able to dig up via google, all for PHP, I bet there are even more:
- Bennu - PHP iCalendar library
- iCalcreator
- iCalendar / vCard parser for PHP (SabreDAV )
- PHP iCalendar
I also wanted to generate a .ics file for a single event. I didn't want to mess with PHP so I was going to use grymala's tip. Unfortunately I did not know the calendarID for the event I wanted to export so I exported all gcal's calendars and edited the resulting file so that it only contained the calendar heading, footing, and vevent lsiting. I also deleted the calendar name thought I don't know if this was necessary.
I never did find out a way to get the url for a specific calendar as gymala suggested but I did find this based on this help text.
In the calendar list on the left side of the page, move your mouse
over the calendar you'd like to export from.
You'll see a drop-down arrow appear next to the calendar name. Click the drop-down arrow and select Calendar settings. (Alternatively, click the drop-down arrow next to My calendars and select Settings, then click the appropriate calendar from the list.)
Click the ICAL button in the 'Private Address' section at the bottom of the page, and click the displayed URL.
Save the exported file to the desired folder on your computer. , possibly by pasting that URL into another browser window, copying the window text,and pasting it into an editor.