Facebook Event exports take two

So a while ago I wrote a php script to make facebook event names appear properly on google calendar.
I’ve since noticed that all ‘full day’ events on facebook get exported as though they are on the previous day! Someone has written a page to do this, but the source code is not available and so it depends if you trust them with your events or not.

As such I updated my php script to do this date change too! Code below, but if you want to use it on my site:
http://www.psykar.com/utils/cal.php?uid=&key=

Get the uid and the key from your events page on facebook by clicking the gear in the top right, and export events, then get the URL of ‘upcoming events’.

For adding this to google calendar use webcal:// instead of http://

<?php

// Facebook uses ZULU time for it's exports.
date_default_timezone_set('Zulu');

function inc_date($matches) {
        $date = new DateTime($matches[2]);
        $date->add(new DateInterval('P1D'));
        return "DT".$matches[1].":".$date->format('Ymd');
}
$ical = "https://www.facebook.com/ical/u.php?uid=".$_GET['uid']."&key=".$_GET['key'];
$file=file_get_contents($ical);

$pattern = "#DT(START|END):([0-9]{8})[\n\r]#";
$file = preg_replace_callback($pattern, "inc_date", $file);

$search="CLASS:PRIVATE";
$replace="CLASS:PUBLIC";
$output=str_replace($search,$replace,$file);
header("Content-Type: text/Calendar");
// Give the file a name and force download
header("Content-Disposition: inline; filename=events.ics");
print_r($output);
?>

One Response to “Facebook Event exports take two”

  1. […] script has been updated to update dates on full day events as […]

Leave a Reply

You\'re not a robot are you? *