How to display Facebook page events on website using PHP?


In this tutorial, I will show you how to display Facebook page events on website using PHP.

Events from your Facebook page are not shown to your website visitors. You spend a lot of time creating, editing, and managing your events. But your fans, audience, and customers from your website still do not see your Facebook events.

Our code in this tutorial will allow you to automatically display your Facebook page events on your website using PHP. Create and edit your events on Facebook and any changes will also be reflected on your website.


This code will get the list of events from your Facebook page. It will show data such as event image, name, time, description, etc. from your Facebook fan page without using any Facebook PHP SDK, just the Facebook Graph API!

We will display these events data on a webpage (assuming it is your WordPress or PHP website.)

We will use a user interface powered by Bootstrap. If you’re not yet familiar with this awesome front-end framework, see our step-by-step Bootstrap tutorial here.

Don’t want to code?

Before we continue coding, if you later realize you do not want to code and need more features, you can use a website plugin called SociableKIT. It is the best no-code tool for the job.

You can easily customize the look and feel of your Facebook page events feed and embed it on your website in 3 minutes. The events feed on your website will update automatically.

Follow this tutorial: Embed Facebook page events on website. You can also use the Facebook group events solution if you use Facebook groups. There’s a free plan that you can use if you don’t need the premium features of SociableKIT.

But if you like coding, continue with our tutorial below!

Final output

We have to know where we are going. If we completed the tutorial below, we will achieve the following output in the video below.

Create the index page

Create index.php file

This page is what will be loaded on the browser. Create an index.php file. Put the following basic HTML code.

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Display Facebook page events on website</title>

    <!-- CSS will be here -->

    <!-- Container will be here -->


CSS code

We’re going to use Bootstrap to make our page look good. We’ll also put some custom CSS. Replace <!– CSS will be here –> with the following code.

<!-- CSS -->
<link rel="stylesheet" href="[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="custom.css" media="screen">

Create custom.css

These are just some additional customization for our user interface. Create a custom.css file. Put the following code.

    margin:30px 0;



Container code

These divs have Bootstrap classes. It will contain our Facebook page events. Replace <!– Container will be here –> with the following code.

<div class="container">
    <div class='col-lg-12'>
        <h1 class='page-header'>Display Facebook page events on website</h1>
        <!-- PHP code will be here -->


PHP code

The code below gets the parameter from the URL about what to display. By default, it is “upcoming” events. The navigation.php file will help the user to select upcoming or past events.

The fb_page_events.php file will contain our request to the Facebook Graph API. Replace <!– PHP code will be here –> with the following code.

$display = isset($_GET["display"]) ? $_GET["display"] : "upcoming";
include "navigation.php";
include "fb_page_events.php";

Create navigation.php file

This file will show two tabs that will allow our users to select upcoming or past events. Create a navigation.php file and put the following code.

$upcoming_class_active = $display=="upcoming" ? "active" : "";
$past_class_active = $display=="past" ? "active" : "";

echo "<ul class='nav nav-tabs'>
    <li class='nav-item'>
        <a class='nav-link {$upcoming_class_active}' href='index.php'>Upcoming Events</a>
    <li class='nav-item'>
        <a class='nav-link {$past_class_active}' href='index.php?display=past'>Past Events</a>

Display Facebook page events

Create fb_page_events.php file

This file will contain the process of building a request to the Facebook Graph API. Create fb_page_events.php file. Put the following code.

// specify date range will be here

// unix timestamp format will be here

// request parameters will be here

// build the api request will be here

// sort to display upcoming events will be here

// looping through events will be here

Specify date range

The code below identifies the “since” and “until” dates that will be used for the API request. For upcoming events, the “since” date is the date today and the “until” date is two years from today.

For past events, the “since” date is the date from two years ago and the “until” date is the date yesterday.

Replace <!– specify date range will be here –> with the following code.

// specify date range
$year_range = 2;

	// date range for upcoming events
	$since_date = date('Y-m-d');
	$until_date = date('Y-12-31', strtotime('+' . $year_range . ' years'));

	// date range for past events
	$since_date = date('Y-01-01', strtotime('-' . $year_range . ' years'));
	$until_date = date('Y-m-d', strtotime('-1 day'));

Convert to unix timestamp

Unix timestamp is required by the Facebook Graph API. We will convert the since and until dates using the code below. Replace <!– unix timestamp format will be here –> with the following code.

// unix timestamp format
$since_unix_timestamp = strtotime($since_date);
$until_unix_timestamp = strtotime($until_date);

Specify request parameters

The variables below are needed to complete the parameters needed for the Facebook Graph API request. Replace <!– request parameters will be here –> with the following code.

// request parameters
$api_version = "v11.0";
$fb_page_id = "YOUR_FACEBOOK_PAGE_ID";

Specify your Facebook page ID and access token

You need to replace YOUR_PAGE_ID and YOUR_PAGE_ACCESS_TOKEN with your own.

To get your Facebook page ID, follow this tutorial. To get your Facebook page access token, follow this tutorial.

We can do this process for you but there will be a service fee of $50. Also, you will need to make us an admin of your Facebook page.

If you want to avail of this service, pay using this link. After the payment, you will receive further instructions from [email protected]

Build the API request

The code below completes the API request link and get the response using file_get_contents() function. We will also decode the response so we can easily retrieve the data. Replace <!– build the api request will be here –> with the following code.

// build the api request
$json_link = "{$api_version}/{$fb_page_id}/events/attending/?fields={$fields}&access_token={$access_token}&since={$since_unix_timestamp}&until={$until_unix_timestamp}";
$json = file_get_contents($json_link);
$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

// for those using PHP version older than 5.4, use this instead:
// $obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);

Sort to display upcoming events

Sorting is needed to properly display the upcoming events. The code below will let the upcoming events to be displayed from the date nearest to today up to the farthest date. Replace <!– sort to display upcoming events will be here –> with the following code.

// sort to display upcoming events
	function sortFunction($a,$b){
		if ($a['start_time'] == $b['start_time']) return 0;
		return strtotime($a['start_time']) - strtotime($b['start_time']);

Loop through events

The code below will loop through each events returned from the Facebook Graph API. Replace <!– looping through events will be here –> with the following code.

// looping through events
foreach($obj['data'] as $event){
	include "extract_values.php";
	include "display_values.php";

Extract and display events data

Create extract_values.php file

In this file, we will extract different types of event data. Create extract_values.php file. Put the following code.

// start date and time will be here

// basic info will be here

// location will be here

Extract date and time

The code below will let us get the event’s start date and time. Replace <!– start date and time will be here –> with the following code.

// start date and time
$timezone=isset($event['timezone']) ? $event['timezone'] : "America/Los_Angeles";

$start_date = date( 'l, F d, Y', strtotime($event['start_time']));

// in my case, I had to subtract 9 hours to sync the time set in facebook
$start_time = date('g:i a', strtotime($event['start_time']));

Extract basic information

The code below will let us get the event ID, name, description, and thumbnail. Replace <!– basic info will be here –> with the following code.

// basic info
$eid = $event['id'];
$name = $event['name'];
$description = isset($event['description']) ? $event['description'] : "";
$pic_big = isset($event['cover']['source']) ? $event['cover']['source'] : "{$api_version}/{$fb_page_id}/picture?type=large";

Extract location

Here we will get the event’s complete address or location. Replace <!– location will be here –> with the following code.

// location
$place_name = isset($event['place']['name']) ? $event['place']['name'] : "";
$city = isset($event['place']['location']['city']) ? $event['place']['location']['city'] : "";
$country = isset($event['place']['location']['country']) ? $event['place']['location']['country'] : "";
$zip = isset($event['place']['location']['zip']) ? $event['place']['location']['zip'] : "";


if($place_name){ $location.="{$place_name}"; }
if($city){ $location.= $location ? ", {$city}" : "{$city}"; }
if($country){ $location.= $location ? ", {$country}" : "{$country}"; }
if($zip){ $location.= $location ? ", {$zip}" : "{$zip}"; }

    $location="Location not set.";


Create display_values.php

The code below will let us display an event item with data we extracted earlier. Create display_values.php file. Put the following code.

echo "<div class='row event_item'>
    <div class='col'>
        <img src='{$pic_big}' class='card-img-top' alt='...'>
    <div class='col'>
        <h2 class='card-title'>{$name}</h2>
        <p class='card-text'>
        {$start_date} at {$start_time}

        <p class='card-text'>

        <p class='card-text'>
        <a href='{$eid}/' target='_blank' class='btn btn-primary'>More info</a>

What People Say About This Code?

I’m so glad that other people are delighted by this code, here are some of them!

From Blog Comments

★★★★★ “Hi Mike, amazing tutorial.” ~ simonerama

★★★★★ “Hello and THANK you for this amazing work! :)” ~ Sergio

★★★★★ “Did the trick for me. Thanks for the nice script!” ~ n0Fear

★★★★★ “Hi Mike, thanks for the great script. I’m a programming novice, but got this running the way I wanted to pretty quickly. I owe you a beer.” ~ Bas Koole

★★★★★ “Hi it’s working great :)” ~ Sebastian

From Emails

★★★★★ “I’ve got it working! You’re a great man, will do some ad for you!” ~ Markus

★★★★★ “Hi Mike! BOOM, works great! Thanks again!” ~ Nick

★★★★★ “Perfect! Thank you very much! If I have some new jobs, I will contact you! Greetings from Germany.” ~ Eric

★★★★★ “Thank you for the fast reply, yes this should work for me. I will contact you again. Thank you so much.” ~ Ruocco

From Facebook Messages

★★★★★ “Hey Mate, code’s a lifesaver (and time saver!)” ~ Andrew

★★★★★ “Thanks, I’ve been trying to get Facebook events on the website for 6+ months had no luck, decided last night to update the site which I haven’t done in a while and thought I’d give it another go and found you’re page through a google search.” ~ Ward

★★★★★ “Mike it’s great and simple! I like! Thank you!” ~ Jasmin

★★★★★ “You’re a life saver, thanks so much.” ~ Brendon

Download the Complete Source Code

You can get the source code by following the whole, well-detailed tutorial above. But isn’t it more convenient if you can just download the complete source code we used, and play around it?

There’s a small fee in getting the complete source code, it is small compared to the value or skill upgrade it can bring you, or income you can get from your website project or business.

For a limited time only, I will give you the source code for a low price. Download the source code by clicking the green buy button below.

Manage events for your Facebook Page and website once Yes
Save time figuring out and coding these features on your website Yes
Display list of all events Yes
Display list of upcoming events Yes
Display list of past events Yes
Display event cover photo (profile picture if none) Yes
Display event title Yes
Display event date and time Yes
Display event location Yes
Display event description Yes
Link to actual Facebook page event (opens in new tab) Yes
Bootstrap UI enabled Yes
Responsive layout (great for mobile devices) Yes
Free email support for 6 months. Yes
Free source code updates. Yes
$50 – Download now

Do you need more reasons to download it?

Buy only once, use up to 10 websites and Facebook pages! Yes
No different kind of licenses. Yes
No monthly or any recurring fees. Yes
No need to rely on another website to render Facebook page events. Yes
No need for codes from other websites. Yes
You can learn more how to code, I love teaching and can give you free tips! Yes
Familiarize yourself with the Facebook Graph API. Yes
Tutorial above is always free. Yes
Completely customizable. Yes

Thank you for supporting our projects!

What’s Next?

Today we have learned how to show your Facebook page events on your website.

Did you know that you can also display Facebook photo albums and photos on your website?

Let us go to the next tutorial: How to display Facebook page photo album on website?

Related Source Codes

We have more tutorials related to social media APIs. Click here.

Some Notes

Found An Issue?

If you found a problem with this code, please send us an email. Before you send an email, please read our our code of conduct. Our team's email address is [email protected]

Please be descriptive about your issue. Please provide the error messages, screenshots (or screen recording) and your test URL. Thanks!

Subscribe to CodeOfaNinja

Receive valuable web development tutorials to your email. Subscribe now for FREE!

Thank You!

Thanks for visiting our tutorial on how to display Facebook page events on website using PHP and Facebook Graph API!

By Mike Dalisay

I'm Mike Dalisay, a pro web developer since 2010. I love web development. Improving our tutorials and source codes makes me happy. Do you want to suggest an edit to our tutorial? Got something to ask about our source codes? You may use our comments section below or email our team at [email protected]


  1. Hi, for some reason I´m actually not able to use “file_get_contents” for the API Url. Just wanted to say that curl works:

    $json_link = “{$fb_page_id}/events/attending/?fields={$fields}&access_token={$access_token}&since={$since_unix_timestamp}&until={$until_unix_timestamp}”;

    $curl = curl_init();

    curl_setopt_array($curl, [
    CURLOPT_URL => $json_link,

    $response = curl_exec($curl);

    $obj = json_decode($response, true, 512, JSON_BIGINT_AS_STRING);

    Hope it helps. Regards Dom

      1. I also experience a problem with showing co-hosted events. In fact they don´t show up, when you use a current timestamp for since. The workaround I use is to set the since-value minus (14 * 86400), exp. 14 days in the past. Later in the process I filter the old events by comparing with the real current timestamp. You can check that behaviour by using Insomnia or Postman with the full JSON-Link – at the graph-API site is the problem. I don´t know if a 14 day period is necessary, but it works for us. Kind regards, Dom

      2. Hi @Dom, thanks for sharing your solution. Are the missing co-hosted events recurring? I encountered a case where you need to query the API with the original event of the recurring event.

      3. No, I our case for the upper solution we had no recurring events that were affected. But I´m interested in the process you mentioned for recurring events, because it seems that only the first of the recurring events shows up unless it´s finished. Thx and regards, Dom

  2. Thanks for the kind words @disqus_yOq0aCGSR8! I believe the “limit” parameter still works. Did you try it?

    If not, you can control to show only two events using a counter in the for loop.

  3. Hi @mdikici, unfortunately, even with the latest API version 3.0, the events API is still turned off. All we can do for now is wait for Facebook to turn it on again.

  4. Hi @disqus_p49iSQMFJj, thanks for the kind words! Unfortunately, Facebook still have the events API turned off. Once they turned it on, that’s the time we can make our next move.

  5. Hi @janvanweert, thanks for reaching out. Unfortunately, Facebook has turned off the events API and all we can do for now is wait for them to make it work again.

  6. Is anyone gettting an error on the this line:
    $json = file_get_contents($json_link);
    It worked for me a few weeks ago last time I checked my site but now I have this error.
    My site is

      1. totally updated to 2.8 already doesn’t change anything. my console error says that the ; on the end of the line need to be a , instead but i know thats the wrong syntax and it kills the php

        i would love to have my events working on my site since im a dj and it used to like a few weeks ago.

  7. Hi,

    It works, but it didn’t show all the events. Some events aren’t show on the website.
    All the events are public and events hosted with more admin are loading also..

    I also checked it with the demo’s (changed the page_id in the link) it didn’t load.

    What could be the problem?

      1. Thanks for the quickly response, sorry i was 2 busy 2 answer till now..
        Don’t know if i can put the full url here, so i do it this way.
        put “onderbroeknijmegen” at the end f the fb url.

        Thanks! This weekend is the event that doesn’t load. So i hope you find it.
        before that date, because every past event loads.

  8. Hello @ninjazhai the code is great! But do you have an idea how I can save the description of a facebook event in my MySQL database if the text of the description includes special chars like ❤ , • …
    I have already tried to convert the string with html_specialchars but it doesn’t work..

    Thanks for your help !:)

      1. Your links were very helpful!
        I have added this line into my code:

        $description = mysql_real_escape_string($description);

        Thank you very much for your help !:)

  9. The code works fine on localhost but when i upload the files on my server it doesnt work…
    $event count is always 0

      1. JSON extension is enabled but allow_url_fopen is only the local value enabled and the master value is disabled .. is this correct or have I to enable both ?

  10. Hello @Marcus, it looks like you’re trying to retrieve events from a personal Facebook account. Unfortunately, our script above only works with public Facebook pages.

  11. Can you make updated article, because this code doesn’t work anymore. When i put myt $json_link to address bar on web browser it returns empty string.

    1. Hello @multigamerr85, our live demo links are working. Our tutorial are updated based on our live demo links. What exactly is the $json_link that you put in the address bar? Do you see any error message?

  12. It works fine but it just show me events which starts from 24th of Mar. 2017 – I’ve tried everything I think, but it’s not possible to show me all events which starts from tomorrow. Help?

  13. Hey there, I could use some help with this… The code works great, and Ive used it on sites before, but the problem I am having now is that the code doesnt work with this one Facebook page I use. It works for all other Facebook pages I try except this one. Is there a setting within Facebook pages that prevents this code from working?

    1. Hello @disqus_fy32CWCXA4 , would you post the link of your Facebook page? Page must be publicly available, please check if your page has something like age restriction. If there is, try to remove it and try again.

    1. Hello @disqus_QTHEjnjOfU, I updated our code tutorial and demos with v2.7, and it still works. We are unable to replicate your error. Tell the any error message you see on your work. Thanks.

  14. hi! Thank you so much for this amazing tutorial!!!
    But how can I change the language? Like its “Wednesday, March 27, 2013 at 12:00 pm” and i want that on portuguese :/

  15. Hi Mike, thanks for the amazing tutorial! I’m just wondering how long the access_token (described in 9.0) will last?! Is it hours, days, months or do these have unlimited lifetime?

  16. Greetings! Thanks for this script. It has been very helpful. I have set it up on a website for a music venue. It displays upcoming events and I am using the re-order script to display them in order from the most imminent. It seems that it is starting with events that are two weeks away instead of displaying the events closest to today’s date. I am using the script in two places on the site. On the Home page and on the Events page. Any thoughts on this? I assume it has something to do with the json data grab.
    Here is the website and its corresponding facebook page:

    1. Hello @BigTonyTheNinja , glad our script helped you! About the issue, you can try to change the $year_range value to 5 or 10, then use the ‘re-order’ script in section 17.0 above.

  17. Hello, thnks for your Doc, its very Interessant and i have used. So, my question is, i want to get all FB Events with Tags or Cateroy . But i dont have any information im internet finded.
    For example :
    Event Name : ABCD
    Start Time : 10.07.2016
    End Time : 13.07.2017
    Interessed : 120 Person
    Category : Musik
    Tags : musik, sport, halloWorld,..

    Plz, have you any Idee ? Thnk you very much

    1. Hello @disqus_izibY1wBsd , thanks for the kind words! About the feature you described, our script cannot do that. But we’ll try to work on it in the future.

      1. Thnk your for your Response, So Yes, your Script cannot do that. I will be very happy to have a positive response.. have a good day :)

  18. I just wanted to thank you again for both the code and for your help! My husband says we owe you a beer! Brilliant work and a very kind person. Thanks again.

    1. You’re welcome @dorisweldonkaz! Thanks for downloading the code and your kind words. Glad to help you with your awesome website. Regards to your husband too. :)

  19. Wow … I was looking to finally do that and It took me few hours to understand facebook doc. Now with your website, it took me 10 min. Thank ! It was very easy to do it and to understand !

  20. Hello @suthemeny, thanks for the kind words! About your concern, would you give us your test URL and FB page URL so we can test it at our end? Which events do you wish to show?

      1. Hi! I figured out what was missing… now it works.. the solution was:

        for($x=0; $x<$event_count && $x<3; $x++){


        I forgot the "and" operator from the line.. now if I have more than 3 events, it only shows the next 3 and if I have less than 3 it shows only 1 or 2 without a fake blank event row… :)

        Thank you for helping,

  21. Hi! I really like this solution to display events on my website!

    I’m a little bit confused… I’m wondering how to define to display only the next 3 events… I made a loop, but if I don’t have 3 upcoming events, only 1 or 2 it displays blank rows with the page profile picture as event image, what I don’t need…

    My loop is:
    for($x=0; $x<3; $x++){
    // here comes the table…

    What I want is to display only the row(s) that have real content.

    Thank you!

  22. Hello thank you SO MUCH for this helpful information.
    THERE is a way to pick the specific events from my facebook acount, that I want to be shown on this tool?

  23. Hey there, I was just wondering how I would go about having the time and dates of the events appear in another language, for example french?

  24. Hello,

    We are looking for a way to retrieve the list of event attendees from Facebook. Ideally, if the attendee has an account on our site (given that he signed up with Facebook), he should be recognized as a user, so we can use this information for the loyalty program. We are using WordPress.

    I’ve been searching for a while already, and none of the available solutions gives the option of retrieving/importing the attendee list. I’m not familiar with the Facebook API and it’s hard for me to imagine what would it take. Could you advise on that?

    Also, would you be interested in developing a plugin like that (or rather a customization to an existing plugin that imports events)?

    Thank you.

    1. Hello @disqus_JsLmgyf2ZS, what you want to do is possible. Facebook graph API allows you to retrieve the list of attendees of an event. You can match users in your database with that information. That way, you will be able to detect if a user attends an event.

      Unfortunately for now, I am working on several projects already and can’t take on another one. Thanks for considering me to develop this kind of plugin.

  25. Hello @disqus_JlaTMSb053, what exactly are you trying to do? Is it the “login with facebook” button? If so, that feature is not covered by our source code above.

  26. Hi there

    Is it possible to add a “Sign Up” button, so the sign up can be done via the website?

    If so I would like to purchase the pro-version :)


  27. Hi, great script! But one question: my sitemap generator keeps adding pages because of each upcoming month, although $year_range = 1; and it won’t quit generating because of all the years ahead ;-) Please advise what to do so I can update my sitemap? #thanx

      1. Just wanted to say thank you. Just purchased the script pro pack today not too long ago and modified it a bit to make it a dark theme and it’s working great. It took a little bit figuring out how to style each individual element, but I have a basic idea now. In any case, it saved me A LOT of time! I read something about having to get an access token from Facebook? Well I just changed the pageid and it seems seems to work. What will i need the access token for? And lastly, is there a place to change pageid and access token globally, or do I have to change it on each page? Thank you!!!!!!!

      2. Hello @daniel_mort, thanks for purchasing the source codes! We are glad you found it useful and saved you a lot of time.

        About your questions, yes it will work with the current access token, but it is more recommended to use your own access token. See the step 7 on how to obtain your own access token. One advantage of having your own access token is, you won’t be affected just in case the current access token had problems.

        About global page ID and access token, currently, you have to change it by page, but we’ll change it in future updates. For now, you can use PHP includes or sessions so it can function like a global variable.

      3. Okay, one last question. How do I sort the events from most recent to farthest away? Upcoming events and all events in particular. Past event’s tab seems to be in the correct order, but there’s only 5 showing of 50+ past events. no page 2 or anything.

  28. Hi..Do you also have any demo script where in pasting the facebook event url will give me all the details of that event.

  29. Thanks for the tutorial. I wasn’t able to make the code work until I found that I had to remove brackets in step 8 Json link. Thought this might help others in the same situation. Cheers

    1. Hello @disqus_7Q6D0fzAdH, you’re welcome! The code works with brackets, I’ve tried it in different servers. Would you tell us the error your faced when you tried to put the brackets?

      1. I put them back and it works nice finally, I wasn’t aware of the “{$var}” syntax so I might solved another error while changing it to ‘.$var.’ sorry for wasting your time.

        I’m currently looking for a way to show events created by users but it seems I need a user access token or something, could you point me some places to look at please ? I’d like to make an upcoming concert list from multiple promoters (pages and users), it works fine with pages as you can see here :

      2. @disqus_7Q6D0fzAdH, your were able to display events from multiple fb pages, that’s cool! But were you able to add an ‘infinite scroll’ feature? About events created by users, yes I think user access token is needed for everything created by users. I haven’t tried to play around with that so I can’t really give a good reference for you..

  30. You can take a look here This is a base of scripts from for get data from Facebook via the “ADS” Dashboard, also have to retrive analytics data from Twitter and Instagram.

    With the base script you can get trends, interests, behavior, demographic, ages, gender qty of every country, city, stage, fanpage from facebook.
    The base of all script are in the WSERVICE folder of the backups folders.

  31. First of all thanks for the excellent tutorial, I already successfully used this code on 1 website. I am running into an issue with the second website I am working on.

    The issue that I am having is that I cannot display the most recent events from my facebook page but can only show events from 2011?

    I have echo’d the since_date and since_date variables to ensure that the dates are correct but no matter what I do I cant get events to show, only events that happened a long time ago in 2011. Is there a limit to the number of events the application can pull?

    I have a feeling this is a facebook issue and not an issue with the code but any insight would be appreciated.

    1. Hello @disqus_0d0j4DwshJ, thanks for the kind words! I’m glad it worked on your website. About your concern, this is a new report, what we usually encounter is the events from 2012 does not show. Would you link us to your Facebook page and test URL so we can investigate more?

  32. How do I change the order of the events? Currently the most future date is showing first in the list. I need them to be in event date order.

    –Update: I did a little research and it seems there isn’t a what to change the order of items in the graph API, so I sort of combined your older FQL version of this with the newer version. It works fine now, since I can change the order from the query. I also think that this wouldn’t work if I had not already created the app before the Graph API was released and I am not sure if FB will just break this sometime soon. But for now, at least it works.

    If you know of a way to do it with the graph API, I’d still love to know it.

    Thanks for sharing your code! I was happy to buy it the second time around because it is very useful for my clients. :)

    1. Hello Vanessa Keeton, unfortunately, Facebook API does not give us the ability to sort the order of events, but I made a workaround for it. Use the following before the ‘for loop’ code:

      function sortFunction($a,$b){

      if ($a['start_time'] == $b['start_time']) return 0;

      return strtotime($a['start_time']) - strtotime($b['start_time']);



      The only disadvantage is that, it will only sort the currently loaded JSON content.

      Thanks for the kind words and sorry for the late reply…

      1. Thanks for the reply! I’ll give this a try next time I am making an update to the site or if I use this on another. :) Thanks again for sharing your ninja skills.

  33. Hey, everything works fine,i am just still modding to use it without bootstrap.
    But is there a way to make it nicer responsive?

  34. Awesome work Mike- great to see the new version using the Graph API!

    One thing though- I noticed the same timezone problems as the fql version. You can see it on the demo of the pro version- just check out the date and time displayed on your page for some of Ed Sheeran’s events and compare them to the date / time of the actual Facebook event. You’ll notice that they’re different because you’re in a different timezone.

    I corrected this in the old version by setting the date_default_timezone_set() value for each individual event to the timezone value of that event. Could you add this fix to the new code as well?

    1. Hello @menathor, sorry for the late reply. You’re correct, for others who are reading, please add the following code inside the ‘for’ loop (see step 11 above)


  35. Hi

    Awesome tutorial. Almost everything works well for me. I just had to change the variable $fields. Facebook says fields “location” and “venue” are deprecated. I replaced it by the field “place” :) Then, you can display the following fields :

    “place”: {
    “name”: “LA SOUTE”,
    “location”: {
    “city”: “Chambu00e9ry”,
    “country”: “France”,
    “latitude”: 45.568758364409,
    “longitude”: 5.916880680781,
    “street”: “Citu00e9 des arts jardin du Verney”,
    “zip”: “73000”
    “id”: “175714291355”

    Thanks a lot for sharing your experience ! (and sorry for my poor english ;) )

    1. Hello @disqus_yTOGsUjuT1, unfortunately, Facebook still doesn’t provide us with a sorting feature even to this date. See my reply to Vanessa Keeton above as alternative solution.

  36. @Chadas, it looks like the JSON extension on your server was not enabled or broken. I replied to you on Facebook how to solve this.

    1. Hello @disqus_2eQpOXlOMe, you’re welcome! You can do it by specifying the event ID on the graph API URL…

      1. Hi! Only the $json_link should be modified? Could you please share a example, how this string should look like in order to meet graph API needs. Thank you!

  37. Can someone tell me how can I add multiple Page IDs to fetch events from? I don’t want just one, I want from more than one. Thank you!

  38. Hi there, I`ve downloaded your src, everything’ s alright, but I get a blank page. Please help me out. thx

    1. Hello @Sergio, you have to replace MY-TOKEN with your own access token… change it in your URL above…

  39. Hi Ninjazhai,

    Is there any way to display the Facebook events on Google Sites website ?

    Thank you for your tutorial.

  40. Hi there…question: do you know if your method works with age-restricted content? A friend has a liqueur business and would like to post his tasting events from FB to his WordPress website. All attempts thus far have failed due to FB’s policies on age-restricted content, so wondering if your solution would solve for that. Thanks!

    1. Hello @bobholling, in this case, I believe Facebook would allow us to pull publicly available data only. No any kind of restriction such as the age-restricted content.

      But I haven’t really tried any workaround on that, maybe it’s possible now but I don’t know how to do that yet.

  41. This works for page events but not events based on a profile. This is the error: Warning: json_decode() expects at most 2 parameters, 4 given. Do you know how to make this work with profiles.

  42. Hello @nicolasleitgeb, yes, it is possible to display events from multiple Facebook pages to one webpage. :D

    1. Yeah :D that was not actually what i meant.I mena events from several pages in one list chronologically.

      1. Oh, yes it is possible, you just have to retrieve all the events first, save them to database, and then retrieve the events chronologically from the database. :)

  43. Hey Guys,
    is it possible to display events of more than one site in one table/list e.g. for band agencies who want to display upcoming events of bands they support…

  44. Hey guys,
    is it possible to display events of two or more fb sites in one list? (e.g. for a Band agency or however to call it in english :D )

    1. followed every step carefully.. doesn’t seem to work for me as well. everything is blank with no error.

      i think it has to do with a setting on facebook dev site?

      1. It’s weird though because his live demo is still working.. I’ve added more functionality to my site and now this is the last thing to do.. He uses FQL in this, isn’t this depreciated unless your facebook application was created months ago?

      2. Hello @disqus_Jqj3qiit9f and @Alan, are you using PHP 5.4+? Would you put error_reporting(E_ALL); at the beginning of your PHP file so that we can see any error message, and tell us here. Thanks!

      3. I’m using PHP version 5.3.29
        and have the following error message:

        file_get_contents(https://graph.faceb….AYB6EeQ): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/dice…e/event2.php on line 57 Notice: Use of undefined constant JSON_BIGINT_AS_STRING – assumed ‘JSON_BIGINT_AS_STRING’ in /hom…ource/event2.php on line 59 Warning: json_decode() expects at most 3 parameters, 4 given in /home/dicetat…k-feed-source/event2.php on line 59

        thanks for your help

      4. Would you guys try to use:

        $obj = json_decode(preg_replace(‘/(“w+”):(d+)/’, ‘\1:”\2″‘, $json), true);

        instead of:

        $obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

      5. Only 1 error now.
        failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
        in /ho..ent2.php on line 55

        line 55 has: $json = file_get_contents($json_link);

      6. The value of your $fql looks weird, why does it have a lot of ‘+’ characters: q=SELECT%0A++++++++++++eid%2…

      7. Hi. Thank you for the tutorial!
        Was this issue resolved? I am getting the same error (online).

        Warning: file_get_contents( …. [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in … on line 32

        (Using $obj = json_decode(preg_replace(‘/(“w+”):(d+)/’, ‘\1:”\2″‘, $json), true);)

      8. @disqus_67ugo85UD5, yes that issue can be solved easily, you maybe have a wrong graph API url or access token, or your server is rejected by Facebook due to high amount of request (problem with shared hosting). Would you give us your test URL?

      9. @Alan, I haven’t actually tried it in localhost, I don’t know if it will work there..

      10. Also this is probably a stupid question but I’ve never used php before – how do I check which version I’m using? I’ve only recently installed it so I’m assuming I have the latest version

    1. You’re welcome @paulmintskovsky, thanks for using our code here! Regarding your issue, your code looks fine, it’s hard to find out what’s the error if it has no error message… would you try to paste your fb page id?

  45. Hello everyone! I updated the source code and tutorial again (September 3, 2014), I did not use the FB PHP SDK this time. Please let me know if there’s any issue, we’ll look into it, thanks!

    1. Hi! Love your work! I was refreshing this page multiple times/day for a new guide….However, there is an issue with the demo page

      1. Hi there @lason! Glad to know you love our work! But what issue do you see in the demo page? Please tell us any error message you see, thanks!

    1. Hello @disqus_l8035fmf9x, thanks for bringing this to my attention, I’m going to update this article asap!

      1. I found this very helpful:

        With that I could build a page to get auth tokens for the pages I manage. After that put together a script to pull a page’s events out of Facebook:

        It runs a bit slower than I’d like as it makes two queries to the graph api (one to pull the ids of the page’s events, a second to pull the details of those ids). I could cache the data returned I guess but there’s probably more headaches in that too.

      2. Thanks for the extra help @disqus_l8035fmf9x, I appreciate it! I’m gonna look into it and try to make it faster or optimized.

  46. Hey Mike, i hope this is still working in general and you can help me. I wanted to integrate this into my homepage but it doesnt work, so i tried it standalone but i only get a blank site with the header… whats wrong there, i used ur code here and did every step very carefully…

    1. Hello @nicolasleitgeb, I think there are some changes in Facebook’s system right now. I will have to update this article asap. Keep up with the updates by connecting with us via facebook or twitter, thanks!

  47. Hi, it is very great tutorial but I faced with problem that I can’t solve, I tried to launch my page with my app id and secret and with my page id but I got this: just everithing goes blank

    here is the code:

    Display Facebook Events to You Website


    ‘secret’ => ‘4b90b95abc7c3e3a0c68f4f583982911’,

    ‘cookie’ => true



    *-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

    * -


    *-As you will notice, we have TWO select statements here because

    *-We can’t just do “WHERE creator = 132064480282039”.

    *-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




    eid IN ( SELECT eid FROM event_member WHERE uid = 221167777906963 )


    start_time >= now()


    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

    * 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’ and ‘end’ 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 “”;

    echo “”;

    echo “”;

    echo “”;

    echo “”;

    echo “{$values[‘name’]}”;


    * -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 “{$start_date} at {$start_time}”;

    echo “{$values[‘location’]}”;

    echo “{$values[‘description’]}”;

    echo “”;

    echo “”;

    echo “”;



    I tested to comment some rows and it seems like problem appears when php comes to this row:
    $fqlResult = $facebook->api($param);

    Do you have ideas why it is so?

    1. Hey @Paul, there are some change in Facebook’s system right now, I will update his post asap. I think that is what’s causing the problem. Please connect with us via FB or twitter for the updates, thanks!

  48. Hi there.
    I have a question. how to replace that instead of a thumbnail display cover?

    1. Hey @bartektalar , good suggestion, please try to look at the events table, there should be a ‘cover’ photo field or something that you can try to access!

      1. Hi!

        The problem has been resolved.
        just under $ FQL = “SELECT pic_cover add and link the image looks
        src = {$ values ​​[‘pic_cover’] [‘source’]}

        fb good job! :)

      1. Hello @disqus_TvXTPgMCK7, would you send a link to your test URL? Also, please make sure JSON and allow_url_fopen PHP extensions are enabled in your server.

  49. And by the…is there any way to change the language from English to any other? Thanks one more time.

  50. Hello and THANK you this this amazing work! :) I still have a problem… I did the proper replacement —-$start_date = date(‘l, F d, Y ‘, strtotime($values[‘start_time ‘]));—- and I have the data showing as 31 December 1969! :( What is wrong? Anyone can Help? Thanks

  51. I think i do have a problem with my app. I always get “Restricted access” at my page. Do I have to set some settings in my App to get access ?

  52. Hi together, i am a real beginner in coding, is it possible to link the Title to the facebook event als an URL? So if someon clicks on the title he gets new page opend with the event? How would i do that?

  53. If anyone elese got the 01.01.1970 Problem. Changing

    $start_date = date( ‘l, F d, Y’, $values[‘start_time’] );


    $start_date = date( ‘l, F d, Y’, strtotime($values[‘start_time’]));

    did the trick for me. Thanks for this nice script!

    1. Hi @mirekmolin, I apologize for the late reply, I see that my code has some problems now due to facebook changes, it looks like you fixed it on your side, can you share us how? Thanks!

  54. Mike, Im new to web design…. really I am a 3D VFX artist trying to pay the bills with web-design. Sadly I am not much of a code person yet. Now, one thing i am getting is that people want to embed or stream their facebook events page to their website. I have created an App ID and App Secret… now what am I doing wrong with your code in this example. I am using Adobe Muse as my web building tool, any help would be appreciated.

  55. Hi
    I successully got this example working with my own fan page however the time and dates are different from those of the actually events on my fanpage. I changed the time zone in the code but this doesn’t fix this. Any suggestions?

  56. Hi Mike,
    First, thanks for this amazing tutorial. I’ve just got a tiny little problem. Today’s event doesn’t appears. At 00:00 the same day as the event it disappears from the site. Any idea how I can fix it?
    Thanks in advance.

  57. Hi Mike, thanks for the great script. I’m a programming novice, but got this running the way i wanted to pretty quickly. I’ve got one thing i couldnt figure out: I would like to use setlocale() to show the weekday in dutch. Could you elaborate how i can implement this in your script? Thanks in advance, i owe you a beer.

  58. Two things I don’t get.

    1) The UID here is hard coded. When I change it to mine or to one of my friends’, I get zero results. Why?

    2) How come you don’t need to be logged in first for it to work?

      1. Thanks for your reply!

        That explains it. I am wondering… If I wanted to get events that were posted to an open, public group (not fanpage):

        1) Would I still not need to log in?
        2) How would I need to change the FQL query to do that? (I’m new to Facebook apps)

  59. I am no PHP or JS programmer and am trying to get the website I uphold for the owners up to date.

    The owners of the cafe put the events on their Fb account, and i am now trying to implement it into their site

    I haven’t got much luck so far getting it integrated. Something is somewhere getting it wrong but I don’t know where and why.

    the test page is:

    My first attempt was http://cafetsjoch/test.html but it was blank in whatever i tried.

    As you can see at the site i use i-frames and ajax-files
    Hopefully anyone can help me.

  60. For anyone having problems with the date showing up like a default date (1969 or 1970), try this:

    Inside the App dashboard click App Settings > Advanced. Set the ‘Events Timezone’ to disabled.
    It is enabled by default. If enabled timestamps are ISO-8601. This does not work with this PHP code.

      1. I see, unfortunately, if the graph does not give the results, this script can’t do the job. It will only work for the publicly available data. I hope in the future, the Facebook graph/SDK will be able to automatically detect if a user is allowed to view restricted contents.

  61. THANK YOU so much for all your work on this and other tutorials. Is there any way to also have the text for the events hyperlinked to the actual event pages??? Thanks again!

  62. Hi Mike,

    just discovered this great script and have it up and running on the following testpage:

    The problem i see is that the description of the event doesnt get formatted the way it is on the facebook fan page.

    For example here:

    you get this:

    “Einlass : 19 Uhr
    Beginn : 20 Uhr

    Erst einmal ist da diese Stimme… großartig und schillernd wie er auf der Stimmpalette tanzt. Von krä…..”

    But on the above testpage with your unmodified script you get all text in one line…:

    “Einlass : 19 Uhr Beginn : 20 Uhr VVK: Erst einmal ist da diese Stimme… großartig und schillernd wie er auf der Stimmpalette tanzt. Von kräfti…”

    How can we fix that? Seems like your script is not reading the breaks from the event-description.


    1. I found a solution to this issue, just change:

      echo “{$description}”;


      echo nl2br(“{$description}”);

      This did the job for me!

  63. Hi,

    i have some problems with the date.

    Whatever I do, I get incorrect date

    wrong day, wrong year.

    i try to change my timezone

    and what i do, i get a wrong date.

    what can i do?

  64. I have problems with the date.

    Whatever I do, I will get a wrong day, wrong month and wrong year.
    I.m from Germany Berlin.

    What should I do?
    I tried: date_default_timezone_set(‘Europe/Berlin’);


  65. Question: My site is not pulling the correct dates and times. It is showing Wednesday, December 31, 1969 at 4:33 pm — Do you have any experience with why that might happen? Is that a default/fallback date? Can I share our test link directly with you for assistance? Thanks

  66. I keep getting this error message, even when changing nothing on your example index.php:

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/twofr0/public_html/bands/ in/home/twofr0/public_html/bands/ on line 49

    I am stuck at this point and could use any help in figuring it out.

    The test page is:

  67. hi mike,
    still trying to solve the problems i’m stuck in:
    i uploaded your scripts to another server (no test server!) and it still doesn’t work. but now i at least get some error codes:

    with “facebook-event-to website” i get:

    Fatal error: Uncaught CurlException: 28: connect() timed out! thrown in /cluster/www/ on line 994

    with “pull-facebook-data/show_events.php” i get:
    Fatal error: Uncaught CurlException: 28: connect() timed out! thrown in /cluster/www/ on line 886

    what am i doing wrong?

  68. hi mike,
    i’ve been trying to make your code run on my website without for several hours without any success. i set up your files, changed the IDs to mine, but when the page loads, it only shows the html part of your script.
    can you tell by this little information where i could have made a mistake?
    thanks in advance, pixie

  69. Mike,

    I wanted to know if you knew of a way to display a url in the event description on Facebook as a link in the event description on the webpage? Any thoughts?

    Thanks in advance.
    Also great tutorial!

  70. Hello,

    what wrong on me?
    Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at /home/asiaterm/public_html/index.php:8) in /home/asiaterm/public_html/fbsdk/src/facebook.php on line 49

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/asiaterm/public_html/index.php:8) in /home/asiaterm/public_html/fbsdk/src/facebook.php on line 49

    This event list is synchronized with this mypage |

    Fatal error: Uncaught Exception: 190: Invalid OAuth access token signature.
    thrown in /home/asiaterm/public_html/fbsdk/src/base_facebook.php on line 1271

    error on my site , how to fix them ? pls help me

  71. Interesting Error…
    this error occurs right out of the box on set up.
    Everything else is fine, but that is an annoying error.

    Undefined variable: prev_button in pull-facebook-datapull_fb.class.php on line 151

      1. yes but what i found so far is the page is not a fan page, it’s a business page, can i convert it or can i get a fan page, basically i need the url to be like, , right now it’s , ok the Blacky page is also one of mine and that one I can get the events to display as well as the photos, but not for the coopkatacombes, is there a way I can convert or request a second url. I have to tell you that facebook is very confusing, ;-)

      2. Ok I fit the problem, was so simple, in the FB setting we had age restriction “over 18” selected, now it work with “anyone 13+” problem solve…

      3. and yes I did have the app ID and secret keys, just see it work with my blacky account, so far what i have found is because the blacky does not have a username for that particular page but the coopkatacombes and the voivod do, is there a way around that

  72. Very helpful though I’ve been spending hours trying to figure out how to use the venue array to show the address info for each event (city, street, state). Any advice?

      1. Thanks for your code @ninjazhai !
        When you query ‘venue’, you get an ARRAY with: id, street, city,state, zip, country, latitude, and longitude

        What can I do to show each one?

      2. You’re welcome Cristiano Andrade! Hmmm can you show me the array? How about something like:

        $id = $your_array[‘venue’][‘id’];
        $street = $your_array[‘venue’][‘street’];
        $city = $your_array[‘venue’][‘city’];

        …and so on..

      3. Yes, that is it. But before, you need to include “venue” on your DB SELECT. Thanks!

  73. Hi

    i have created the app as you described and coiped the app id and secret to the index.php. I filled in my uid and tried it on my web with no success. i don´t get any errors, the web is just all white and blank.

    My webhost runs php “Version: 5.2.10-2ubuntu6.10” and i copied all the other files in same structure you described.
    Do i have to prepare the app with permissions, other details to be able to read from my events_menber db?

      1. Hi again
        It seems like that my webbrowser not will run the code under the body tag, i viewed the source after i loaded the site and it only showed the css and the body tag and nothing more.

  74. Hi Mike,
    Only one thing, I suggest to convert the date in PHP as follows:

    $starttime = ”.$values[‘start_time’].”;
    $st = new DateTime($starttime, new DateTimeZone(‘PST’));
    $st -> setTimezone(new DateTimeZone(‘CET’));

    format(‘d-m-Y H:i:s’); ?>

    To avoid the PHP error “A non well formed numeric value encountered”.

    Btw amazing tutorial.

  75. Hello Mike

    Thank you for your examples!

    I recently used your example for load photos from Facebook using my app id and secret, and it works on any page (even if mine or not) i proved.

    Now, i proved this code on two pages: COAN-Dummy-Page and AwenMasajes (my own page), but this code works only on your page, using my app id and secret.
    I don’t understand what is access token, what is the difference between that and my app id and secret.

    Do you have any idea of what i have to do?

    Thank you very much, again.

    (sorry for my poor english)

    1. Hi pepe, thanks for dropping by! Access token is used when you want to pull photos from a Facebook profile, but this script can be used only for Facebook fan pages.

      1. That’s what i did. But your code olny works on the fanpage COAN-Dummy-Page and doesn’t work on my fanpage AwenMasajes. I don’t know what is the difference betweeen them. What i have to do with my fanpage? The code is the same, only change the fanpage’s id.

      2. I’m sorry for wasting your time. I dont know what i did, but it works now. Thank you for all.

  76. All works, but above the events i get the following code. What does this mean?

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /kunden/webseiten/stephan/contao/facebook/index.php:47) in/kunden/webseiten/stephan/contao/facebook/fb-sdk/src/facebook.php on line 49

    1. Hi Sebastian, you can append limit 0,3 to the query to limit results to 3 events.

      Maybe you can limit the description to 15 words by doing $descriptionArr = explode(” “, $description); and then loop through it to get the first 15 items (words) to compose the 15-word description.

  77. hi mike – great script but there is a solution for the timezone
    problem? the note on the fb developerpage does not bring me more, im not
    a programmer ;-( for example: im setup following data (see attachment)
    the result is – on Thursday, January 01, 1970 – 1:33 am to 1:33 am –
    see on
    many many thanks in advance

  78. For the Problem with 31 December …. copy the following code to your Index.php
    and change your date_default_timezone_set…

    $start_date = $values[‘start_time’];
    $timestamp = strtotime($start_date);
    $start_date = date(“d.m.Y”, $timestamp);

    $start_time = $values[‘start_time’];
    $timestamp = strtotime($start_time);
    $start_time = date(“H:i”, $timestamp);

    1. Thanks Michael! Or to be shorter, you can do something like:

      $start_date = date(“d.m.Y”, strtotime($values[‘start_time’));
      $start_time = date(“H:i”, strtotime($values[‘start_time’]));

      1. Type in ninjazhai’s $start_date line. It should be:

        $start_date = date(“d.m.Y”, strtotime($values[‘start_time’]));

    1. Hi Tom,

      I see you got it working on your website. Mind sharing your code? I’m using it for a Dutch website and the date and time is just messed up. The date says Wednesday, December 31, 1969
      10:00 – 4:00 pm and I’ve tried any fixes for it posted on here. As you’re Dutch too, did you edit anything specifically?

  79. Hello Mike,

    I really neeed your help man!

    In your Photo Album post, I am getting following error,

    Please help me to solve it…

    Fatal error: Uncaught Exception: 102: Session key invalid or no longer valid thrown in /Applications/XAMPP/xamppfiles/htdocs/facebook/fb-sdk/src/facebook.php on line 515

    [email protected] is my email ID. Please some one help me to solve it.

  80. Thanks for the script! This is a huge time saver! Unfortunately, I am having trouble with calling the venue. I have added venue to the SELECT query. When I call it by using echo $value[‘venue’]; it returns “array”. When I call the city with echo $value[‘city’]; nothing is returned. HOWEVER, other queries work perfect (name, description, start_time, and location).

    Not sure if this is from how I am creating the event? I am tagging a business in the “where” field when I create the event. The address shows in the event, but it will not let me get the city and state.

    I’m new to all of this; sorry if this is a stupid question. :(

    Any suggestions?

  81. Hi Mike,
    I have a question for you.
    Instead of Facebook Pages, Can we create and export events from a Facebook Application?
    I had created an app in Facebook, and I want to create/export events from facebook to my website and also from my website to facebook app.
    Is this possible?
    Please Help!

  82. Dear Mike, thanks a lot for this tutorial. I have one question. Is it also possible to let people react to an event from your website. I want the option that people can give up their RSVP from my website, so they don’t have to go to Facebook.

    Kind regards, dennis

  83. On July 5th, Facebook changed something with the timezones and now I am getting December 31, 1969 for all event dates. Is anyone experiencing this?

    I even get the wrong dates using the sample files downloaded above, put directly on my server, unedited (aside from app id, etc). However, the live demo seems to be fine. How?


  84. Hi, Just asking once more, why the events has not showed up on my page?

    I created an app on facebook, and entered all the information into the widget.

    Is there anything more to do from here?

  85. oke I already has the answer…

    date_default_timezone_set(‘America/Los_Angeles’); is working, so I changed it by date_default_timezone_set(‘Europe/Amsterdam’);

    sorry for bothering you


  86. Heee Mike, The +9 hours doesn’t work anymore, how come…>

    Still has the code:

    $fql = “SELECT eid, name, pic, start_time, end_time, location, description FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 162678887146825 ) AND end_time > now()+(9*60*60) ORDER BY start_time asc LIMIT 0,3”;

    and date_default_timezone_set(‘America/Los_Angeles’);

    He doesn’t raise the time with 9 hours…!!!


  87. Hi, I have managed to create an app on facebook and fill in all the boxes in the widget.

    But nothing is showing up on my webpage. – Should i wait for you to get the codes up on your index.php file?


  88. This is great and works well, but I’d like to list the profile image of those attending each event.
    Any idea of how I could add that to the code so when each event lists, it shows perhaps a random 5 people who have marked the event as ‘attending’?

  89. Thx for this code!
    How can I add an option to translate the dates? I’ve seen that two people asked the same thing but no answer yet at least on this page ;) Isn’t something as easy as a param ? Thx in advance!

  90. How to make it FQL from events change to share links?

    I changed your coding on the FQL, but the image not work
    Result after changed your coding there

    Since I can post the coding on your blog…
    So I upload the index.php to my blog for your reference what is wrong on it.

    Thank you of your time and help and share this coding.

    Best Regards,
    Jimmy Chan

  91. Excellent script and very well documented.

    My question is that no matter what I do I can not fetch the last three events, I only seem to get the current and future events.

  92. Hee Mike,

    Jeroen gave me the right answer by set the timezone on America/Los_Angeles. Thanks to Jeroen.

    Just another question: Is it possible to add also the Venue with the google-map for the location ?


  93. Hello Mike,
    thanks for your great script. Works!
    but I seem to have the same problem as Arthur, even if i put my timezone in your script.

    The scripts adds 9 hours??

    What am I doing wrong? Thanks. Jeroen

  94. Dear Mike,

    Thanks for your tutorial:

    It works great, but just have a question concerning startdate/starttime and enddate/endtime.

    I add an event which start at 07 april at 21:30 and ends at 08 april 01:00. But at the site it shows only:” on Sunday, April 08, 2012 – 5:30 am to 10:00 am “



    How can I change this in index.php

    Thanks in advance

    1. Hee Mike,

      I did some alterations with:

      $fql = “SELECT eid, name, pic, start_time, end_time, location, description FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 162678887146825 ) AND end_time > now()+(9*60*60) ORDER BY start_time asc LIMIT 0,3”;

      But still the output is California time….

      Please can you help Jeroen en me…!!


    2. hoi Arthur,
      oplossing is bizar simpel. In het script van Mike tijdzone op America/Los_Angeles laten staan en je evrnts worden goed getoond.
      Wel rekenen als je een eindtijd exact op het moent van je lijst wil.
      groet Jeroen

  95. Excited to say I’ve been able to take your code and actually implement it, so, before I ask a question–THANK YOU!

    Here’s the page that will have the Facebook Events feed:
    It should be pulling data from:

    Not sure why, but I’m getting a display of old events. Note that the first four events on my site’s feed are outdated, and if you visit the Facebook page it is supposed to be pulling from, you’ll see there is a new event (Best of Richmond Thank You at The Empress) that it isn’t listed on my custom feed. Any help would be greatly appreciated!

    1. Ali,

      In order to display only current and future events you need to add “AND end_time > now()” to the end of the SELECT statement:

      For details please see my post in reply to @s0uky on Jan 29 above.


  96. I’m sorry. I really want to use this for my website, but I have no idea how to even get started using these type of things. is their a video or can you walk me thru the steps of putting this where it needs to go> I absolutley am clueless when it comes to this stuff.

  97. Thank for a job well done.
    Pls i want to be able to get information from Facebook with the keywords on Nigeria, Events, Wedding, Make Up Artists, Mobile Network, Photographers etc. This is not just on a particular fan/friend. Kindly assist

  98. This is a great code sample. Many thanks for posting. I have been trying to create an equivalent snippet using JavaScript. Unfortunately the ‘select’ statement seems to blow up.

    As a test I ran
    “SELECT name, venue, location, start_time FROM event WHERE eid = xxx”. This works.

    However ‘SELECT name, pic, start_time, end_time, location, description FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = yyy ) ORDER BY start_time asc” does not seem to work

    Here is the code snippet. Any ideas


    var fql_query = ‘SELECT name, pic, start_time, end_time, location, description FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = xxx ) ORDER BY start_time asc’;


    var query = FB.Data.query(fql_query);

    query.wait(function(rows) {
    alert(‘query results’);


  99. I want to use this on a site but I am having a hard time understanding APP Ids. I don’t own the Facebook account or web site I am using. Would I need to log in to Facebook under my clients name, create a ID with that? Then this ID is associated with that user? Or do I create an account for development purposes with Facebook and then I can develop for other sites with one ID. Just don’t understand how myself, the website and Facebook all interact.

    1. Hi Anonymous! Yes you have to own a Facebook account. You can create a new account for your clients or just use your own FB account (I actually use my own FB account, haha!).

      I recommend creating a new ID for each of your app. For example you have created an app ID for, you have to generate another id for

      This link will get you started when you want to develop FB apps for websites or

  100. Hi Mike
    I have found what I have make wrong – I haven’t us the same directory structure to the facebook library….shame on me :-)
    No it’s works very good. Great that u share that knwoledge! Thanks a lot

  101. Hi, unfortunately it’s not working for me.
    I don’t understand where I can find the APP_ID_Secret for “Events” – this is a Facebook App – how can I get a secret ID to that public APP?
    The appID for Events is ‘2344061033’ is there more?
    On my developer Page I see the appID and the secret ID all of my fanpage working apps …but those one are useless here I guess :-(
    I think I missed some important things here ;-) Anybody who can help me?

  102. Thanks for this Mike – It’s very useful, good job.
    My question is if you can give me some instructions regarding how to place an fb event attending button on my webpage? I searched for it many places, but nothing useful yet. Thank you in advance.

  103. Alright, galleries and events, pretty easy, how about status’? I fake code pretty well and I’m good at reading it, but my strong suit is design and frontend tech, so bear with me…

    I’ve got my select statement:

    SELECT message FROM stream WHERE source_id=PAGE_ID AND actor_id=PAGE_ID

    I’ll probably build on this once I get this working, but I assume I can add various element from a status, such as image, timestamp, etc. I need to create variables for each of these then output them to the HTML with a little CSS. Anythign I’m missing?

    I’ve been doing some research that says you can’t pull imagery or links from status, but I would think if you have permission and pull the gallery, then you should be able to grab that img ID somehow.. any ideas or tips?

    I’m a newbie to FQL, so any help is appreciated.

    1. I was able to get this simple statement working, I even added a couple parameters to grab the timestamp, name, and a couple other things. What I couldn’t figure out was how to pull over pics. the more I searched through Fb Developer network, the more I kept running into the same script: fbWall.

      Given some time and maybe some help from a better developer than me, I probably could have eventually got it, but this script does exactly what I want it to. I may try and deconstruct the script to see what I still needed to do in order to get it to work.

    2. Like box and actually fan box have too many limitations first and foremost width and style requirements. fbWall eliminated all that it allows you full control over the feed enabling you to easily customize every part to better fit your site and design needs.

  104. @s0uky,

    To display future and current events only – but not past events – an addition to the $fql SELECT statement is required, as mentioned in my earlier post above.

    If you add “AND end_time > now()” to the end of the SELECT statement this will ensure that past events are not displayed:


    $fql = “SELECT eid, name, pic, start_time, end_time, location, description
    FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 123456789012345 ) AND end_time > now()
    ORDER BY start_time asc LIMIT 0,3″;

    Please Note: as Facebook is based on California time – which was set in this php code at the start – you need to adjust the end_time part of the statement above if you are not in California.


    California is GMT-8 hours so as I’m in London I need to add 8 hours to the Facebook end_time to get it to match my local time – so the end time statement becomes:

    AND end_time > now()+(8*60*60)

    Note: Time is calculated in seconds so we have the time difference from California of 8hours x 60minutes x 60 seconds.

    Of course you need to calculate the time difference in your local area for this to be correct for you. Just replace the 8 in the statement with the time difference in hours from California – 9 for CET for example.

    By using the event end_time rather than the event start_time your webpage will display events which are still current. If an event is on from 10am – 4pm it will be displayed on your web page until 4pm – after which time it becomes a past event and will no longer be shown.


    1. Thank you! I’ll try it.

      I done it with PHP function strtotime().
      It works too, but it’s little bit complicated:

      $start_time = date( ‘g:i a’, $values[‘start_time’] );
      $end_time = date( ‘g:i a’, $values[‘end_time’] );

      $datum_akce = date(‘j-n-Y’, $values[‘start_time’]);
      $aktualni_datum = date(“j-n-Y”);

      if (strtotime($datum_akce) >= strtotime($aktualni_datum)) {
      //printing the data

  105. Hello,
    for first – thank you for script, it’s very good job!
    And now I need little help…
    Is it possible import from FB only future events, not past?


  106. Hi, i get the events on my webpage but the i want the timeformat to be 24H and the language to be in swedish on the name of the days and months. How do i fixe this?

  107. This is great. Thank you… but…

    Instead of events, I’m getting the below errors. Any ideas?

    “Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at /index.php:9) in /fb/src/facebook.php on line 37

    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /index.php:9) in /fb/src/facebook.php on line 37″

  108. Hi.
    Like Wella, I think this feature is awesome. BUT. I dont have any Appid, as I have made my fan page without developer.
    So what I really have is a url and thats it.

    Is it possible for me to show the events on my website?

  109. Hey

    This code ist really awesome and i just built it into my page and formatted it like i wanted to. But I only get it worked wth your “page id”.

    The Fanpage that I wanted to display is ->

    I simply have to copy the Fanpage-ID or not? Or it’s the APP-id? User-id? And put it on the SQL Query?

    like: … IN ( SELECT eid FROM event_member WHERE uid = 318385904895 ) …

  110. Thanks for this Mike – It’s very useful.

    @Aditya Nayak asked is there a way to link to each individual event?

    As Mike said in his reply to @heyitshenryy: “You just have to wrap each event record with an href to a link”

    Obviously you will first need to find the eid value of the event to create the link. You get this by simply adding “eid” (without the quotes) to the SELECT statement.

    I used the following to select the next three events – change the LIMIT number to get the number of events you need (NOTE: using end_time > now() ensures that today’s events are included in the list but not past events)

    $fql = “SELECT eid, name, pic, start_time, end_time, location, description
    FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 123456789012345 ) AND end_time > now()
    ORDER BY start_time asc LIMIT 0,3″;

    I made each event clickable by adding a href link to the //printing the data section around the whole <div class=”event”> element:

    i.e. I changed

    //printing the data
    echo “<div class=’event’>”;


    //printing the data
    echo “<a href=’{$values[‘eid’]}’ title=’Click for more details on the Facebook Event page’><div class=’event’>”;

    and I closed the link by changing the last line of this section from

    echo “</div>”;


    echo “</div></a>”;

    I hope this helps.

  111. thanks, works fine so far… two things:

    1) how do i translate the date into another language (german, french…)?

    2) how to get street and city for the location? when i put in “venue” instead of “location” it outputs “Array”…

    thanks in advance for any help!

  112. Does anyone know the code that unknown wrote earlier?
    “I have the code working but I would like to group events together like facebook such as…
    This week
    How would I change the code to achieve this???”

    Thank you all for your help!

  113. Thank you so much for this. Been digging through the SDK and tutorial all day and I just couldn’t find my way through them.

    I see that there are lots of “thank you” comments. You can be proud !

    Alain, Paris, France.

  114. I got this error on your plugin:

    Caught exception: Protocol https not supported or disabled in libcurl

    Any ideas?

  115. I have the code working but I would like to group events together like facebook such as…
    This week
    How would I change the code to achieve this???

  116. Ok I got this to show the events of a Group and personal facebook profile but I cannot get this to produce events of a Page created for the business, how do i configure the php to show a FB page events?

  117. Hi Mr Dalisay,

    i am not really into the material, so i dont get it: what are the steps that i need to do to display the events of my fansite to my existing webpage?
    Could you help me?

    Thanks a lot


  118. @souzapaul, I just tried changing the following in index.php to show the top most recent events, thats all I need:

    $fql = “SELECT name, pic, start_time, end_time, location, description

    FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 124398140915524 )
    ORDER BY start_time DESC LIMIT 0,10″;
    // ORDER BY start_time asc”;

    -Mike Quick

  119. Hey, thanks Code Ninja! It took me much longer than it should have to get this working but it was because despite having a degree in CompSci, I don’t do this type of stuff nor did I know if I was talking to FB correctly. The Examples and tests phps didn’t work for me but the index.php worked great. So after spending time on all of that stuff I figured out some very basic directions:

    1. create the app (like you said), I put in in for web page

    2. save the code zip file and extract it, edit the index.php file: you will need the code and secret from the app you created in step 1, AND you will need the UID for the web page. If you don’t know it you can get it from one of the other iframe apps like the like’ button for your website.

    3. in index.php , put in your code and secret where it says, and also change your uid lower in the doc. save.

    4. upload index.php and the folder fb-sdk folder. to some place on your server.

    5. test the page.
    -Mike Quick

  120. @souzapaul: I think its a yes. as long as it is a public event. you have to do multiple queries. For your Q2, “WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 221167777906963 )”, this part of the script actually allows you to add multiple eids.

    @Romymk: maybe using the LIMIT clause on your sql query?

  121. I got an error like “Fatal error: Call to undefined function: date_default_timezone_set() in C:inetpubvhostshttpdocsfacebooktestindex.php on line 19”

  122. Hi Mike,

    I’ve replaced the app id & secret with my own, however my page events are not appearing. Am i missing a step? Is there a certain way to integrate facebook pages with apps?

  123. Hi Mike. Yeah, theres a link in 1_7 events to take you to events.php. What I want is to get rid of that link… have the results from the php show up directly in 1_7.. I’ll check out include, thanks.

  124. @rich: currently, i see the event menu link is in, not in

    i guess you want to include on your index.php, if you’re familiar, you can try something like include ‘events.php’; at the content part of you index

    @Andrew: Sorry man I only tried this with PHP. But I believe that there’s also a facebook sdk for and just use the same approach I used here.

  125. This is exactly what I require but in Do you know of a link where I can find an version of do you have one?

    Thank you

  126. Hi, relative noob im afraid. I’ve got the above working when I go to domain/events.php, works great. However, I know want to call the script from my menu_7.html file. Any ideas?

  127. @lsm007: You may try to Edit your event and choose “Add street address” option to specify your city and then save changes. And in our script, call $values[‘venue’].

  128. Can I call the “city” that the event is hosted in? I checked the API documentation and it said to use $values[‘venue’][‘city’], I think…but that’s not working. Thoughts?

  129. not to sound like a total noob, although i am, is there a way to do this automatically when a new event is created? I’m creating a fan page for a client, and don’t want them to have to constantly update the page. i’ve tried googling it and got nothing.

  130. @Beat Culture Evolution: It is possible to show events from multiple fan pages but not personal profile accounts. You just have to do another query with your other fan page id specified.

  131. Hmmm are you talking about facebook business accounts? Sorry I haven’t tried it yet since I don’t have one.

    Please note that this script works with facebook pages only, not personal fb account.

    Thanks for your comment. :)

  132. Will this work for a Facebook BUSINESS Page?

    I’ve struggled with getting a Charity’s Facebook Business Events Calendar to synchronise with Google Calendar on their website.

    It seems Google Calendar likes ‘personal’ Facebook URL’s (found via Facebook>Events>Export) but doesn’t like Facebook’s ‘Business Page’ URL’s Note the slightly longer UID in the following Facebook Business Page for above said example…

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top