Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Facebook Event List

Posted on December 19, 2013October 26, 2015 By David Kittell

This is not my work (Mike Dalisay), simply posting as I found this code useful.

After creating an app, we’ll have the following codes on our index.php file

    <style type='text/css'>
    body{
        font-family: "Proxima Nova Regular","Helvetica Neue",Arial,Helvetica,sans-serif;
    }

    .clearBoth{
        clear: both;
    }

    .event{
        background-color: #E3E3E3;
        margin: 0 0 5px 0;
        padding: 5px;
    }

    .eventImage{
        margin: 0 8px 0 0;
    }

    .eventInfo{
        padding:5px 0;
    }

    .eventName{
        font-size: 26px;
    }

    .floatLeft{
        float:left;
    }

    .pageHeading{
        font-weight: bold;
        margin: 0 0 20px 0;
    }
    </style>
//we have to set timezone to California
date_default_timezone_set('America/Los_Angeles');

//requiring FB PHP SDK
require 'fb-sdk/src/facebook.php';

//initializing keys
$facebook = new Facebook(array(
    'appId'  => 'changeToYourAppId',
    'secret' => 'changeToYourSecretId',
    'cookie' => true
));

//just a heading
echo "<div class='pageHeading'>";
    echo "This event list is synchronized with this ";
    echo "<a href='https://www.facebook.com/pages/COAN-Dummy-Page/221167777906963?sk=events'>";
        echo "COAN Dummy Page Events";
    echo "</a>";
    echo " | ";
    echo "<a href='http://www.codeofaninja.com/2011/07/display-facebook-events-to-your-website.html'>";
        echo "Tutorial Link: Display Facebook Events To Your Website with PHP, FQL and jQuery";
    echo "</a>";
echo "</div>";

/*
 *-Query the events
 *
 *-We will select:
 *  -name, start_time, end_time, location, description
 *  -but there are other data that you can get on the event table
 *      -https://developers.facebook.com/docs/reference/fql/event/
 *
 *-As you will notice, we have TWO select statements here because
 *-We can't just do "WHERE creator = your_fan_page_id".
 *-Only eid is indexable in the event table
 *  -So we have to retrieve list of events by eids
 *      -And this was achieved by selecting all eid from
 *          event_member table where the uid is the id of your fanpage.
 *
 *-Yes, you fanpage automatically becomes an event_member once it creates an event
 *-start_time >= now() is used to show upcoming events only
 */
$fql = "SELECT
            name, pic, start_time, end_time, location, description
        FROM
            event
        WHERE
            eid IN ( SELECT eid FROM event_member WHERE uid = 221167777906963 )
        AND
            start_time >= now()
        ORDER BY
            start_time desc";

$param  =   array(
    'method'    => 'fql.query',
    'query'     => $fql,
    'callback'  => ''
);

$fqlResult   =   $facebook->api($param);

//looping through retrieved data
foreach( $fqlResult as $keys => $values ){
    /*
     * see here http://php.net/manual/en/function.date.php
     * for the date format I used.
     * The pattern string I used 'l, F d, Y g:i a'
     * will output something like this: July 30, 2015 6:30 pm
     */

    /*
     * getting start date,
     * 'l, F d, Y' pattern string will give us
     * something like: Thursday, July 30, 2015
     */
    $start_date = date( 'l, F d, Y', $values['start_time'] );

    /*
     * getting 'start' time
     * 'g:i a' will give us something
     * like 6:30 pm
     */
    $start_time = date( 'g:i a', $values['start_time'] );

    //printing the data
    echo "<div class='event'>";

        echo "<div class='floatLeft eventImage'>";
            echo "<img src={$values['pic']} width='150px' />";
        echo "</div>";

        echo "<div class='floatLeft'>";
            echo "<div class='eventName'>{$values['name']}</div>";

            /*
             * -the date is displaying correctly, but the time? uh, sometimes it is late by an hour.
             * -it might also depend on what country you are in
             * -the best solution i can give is to include the date only and not the time
             * -you should put the time of your event in the description.
             */
            echo "<div class='eventInfo'>{$start_date} at {$start_time}</div>";
            echo "<div class='eventInfo'>{$values['location']}</div>";
            echo "<div class='eventInfo'>{$values['description']}</div>";
        echo "</div>";

        echo "<div class='clearBoth'></div>";
    echo "</div>";

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type='text/javascript'>
    //just to add some hover effects
    $(document).ready(function(){
        $('.event').hover(
            function () {
                $(this).css('background-color', '#CFF');
            },
            function () {
                $(this).css('background-color', '#E3E3E3');
            }
        );
    });
</script>

Credit Goes To: Mike Dalisay @ http://www.codeofaninja.com/2011/07/display-facebook-events-to-your-website.html

Originally Posted on December 19, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code JavaScript jQuery PHP

Post navigation

Previous post
Next post

Related Posts

Directory Listing

Posted on May 20, 2014October 26, 2015

dir *.pdf /O:N /b > filelist.txt Originally Posted on May 20, 2014Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully…

Read More

Create Shortcut (VB, VB.Net, PowerShell)

Posted on December 14, 2013December 10, 2019

Sub Create_ShortCut(ByVal TargetPath As String, ByVal ShortCutPath As String, ByVal ShortCutname As String, Optional ByVal WorkPath As String = "", Optional ByVal Window_Style As Short = 0, Optional ByVal IconNum As Short = 0) Dim VbsObj As Object VbsObj = CreateObject("WScript.Shell") Dim MyShortcut As Object ShortCutPath = ShortCutPath MyShortcut =…

Read More

Execute SQL

Posted on April 20, 2015October 26, 2015

protected void ExecuteNonQuery(string sql) { SqlConnection sqlConn = new SqlConnection(); try { string connString = ConfigurationManager.ConnectionStrings["DbConnection"].ToString(); sqlConn.ConnectionString = connString; sqlConn.Open(); SqlCommand sqlCommand = new SqlCommand(sql, sqlConn); sqlCommand.ExecuteNonQuery(); } catch(Exception ex) { labelSuccess.Text = ex.Message; } finally { if(sqlConn.State == System.Data.ConnectionState.Open) { sqlConn.Close(); } } } Originally Posted on April 20,…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes