Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created May 29, 2011 17:36
Show Gist options
  • Save cognitom/997980 to your computer and use it in GitHub Desktop.
Save cognitom/997980 to your computer and use it in GitHub Desktop.
Export ical format for Facebook page's events
<?php
// https://github.com/facebook/php-sdk/
require_once 'path/to/facebook.php';
// http://www.kigkonsult.se/iCalcreator/
require_once 'path/to/iCalcreator.class.php';
$config = array(
'appId' => 'xxxx',//change to your fb app id
'secret' => 'yyyy',//change to your fb app secret
'pageId' => 'shimokitazawa.osscafe',//change to target fb page id
'timezone' => 'Asia/Tokyo',
'timezoneDif' => 9*60*60,
);
$facebook = new Facebook(array('appId'=>$config['appId'], 'secret'=>$config['secret']));
$page = $facebook->api('/'.$config['pageId']);
$v = new vcalendar(array('unique_id'=>$config['pageId']));
$v->setProperty('method', 'PUBLISH' );
$v->setProperty('x-wr-calname', $page['name']);
$v->setProperty('X-WR-CALDESC', $page['name']);
$v->setProperty('X-WR-TIMEZONE', $config['timezone']);
$cons = $facebook->api('/'.$config['pageId'].'/events');
$event_ids = array();
foreach ($cons['data'] as $con) $event_ids[] = $con['id'];
$events = $facebook->api('?date_format=U&ids='.implode(',', $event_ids));
foreach ($events as $event){
$e = & $v->newComponent('vevent');
$d = explode(',', date('Y,m,d,H,i,s', $event['start_time']-$config['timezoneDif']));
$e->setProperty('dtstart', $d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
$d = explode(',', date('Y,m,d,H,i,s', $event['end_time']-$config['timezoneDif']));
$e->setProperty('dtend', $d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
$e->setProperty('location', $event['location']);
$e->setProperty('summary', $event['name']);
$e->setProperty('description', $event['description']);
$e->setProperty('url', 'http://www.facebook.com/event.php?eid='.$event['id']);
}
$v->returnCalendar();
@phibo23
Copy link

phibo23 commented May 24, 2012

Hi, I've been looking for something like this for a long time, so I want to thank you with a Flattr donation. You can claim it here: https://flattr.com/thing/694182

@akostadinov
Copy link

Anybody made this work with the new graph sdk?
https://github.com/facebook/php-graph-sdk ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment