Wednesday 21 March 2012

Display Facebook events feed on website

Share |
Display Facebook events feed on website - From events created from profile, not the Fan Page

Many wordpress plugins at this point in writing did not seem to offer a solution to me. What I am trying to do here is to simply pull out a Facebook event feed and display them on my wordpress page. Meaning event feeds from Facebook with URL format http://facebook.com/events/123456789123456/ for example.

Many implementations out there work for events created from page events instead, those of URL format https://www.facebook.com/pages/Page-Name/123456789123456?sk=events
(A another version on my issue here: http://www.codeproject.com/Questions/348664/Trouble-with-embedding-facebook-events-on-wordpres)

I tried wordpress plugins like facebook-feed-grabber.0.6.zip and jsl3-facebook-wall-feed.1.3.1.zip but they did not do what I needed simply, which is NOT get feeds from Fan Page events.

My PHP implementation here:
1. Have a Facebook app ready for this (https://developers.facebook.com/apps)
2. Get a copy of the Facebook php sdk and put it in your desired folder (https://github.com/facebook/facebook-php-sdk)
3. Create a php file with these few lines below which will allow you to get the feed from your Facebook public event:

<?php 
require 'fb-sdk/src/facebook.php';
$facebook = new Facebook(array(
    'appId'  => 'REPLACE-WITH-FACEBOOK-APP-ID',
    'secret' => 'REPLACE-WITH-FACEBOOK-APP-SECRET',
));
$pageFeed = $facebook->api('REPLACE-WITH-FACEBOOK-EVENT-ID' . '/feed');
?>


(FACEBOOK-EVENT-ID will be 123 if your event url is http://facebook.com/events/123/ )

4. The $pageFeed is an array containing all your event feed details. You can then for example get your first event name with $pageFeed[data][0][name].
5. You can then manipulate this array as you wish and decorate it with some nice CSS styling
6. Finally, if you are using wordpress, you can use the iframe html tag to include this new php file into your wordpress page.

Captured details from Facebook public event