justb3a

module
Facebook Events

14 posts in this topic

FacebookEvents

ProcessWire module to get Facebook Page Events using the Graph API.

Create an app on Facebook developers website

You have to create an app to get appId and appSecret. Those keys are required.
Go to Facebook Developers and add a new app.
Congrats! Now you can copy your Facebook appId and appSecret.

Get your Facebook page ID

You can either enter your facebook page ID or the facebook page name.
If you enter the Facebook page name, this module will get the page ID for you!

Call Module

$events = $modules->get('FacebookEvents')->getEvents();

Output Events

{% for event in events|reverse %}
  {% if event.start_time|date('U') > date().timestamp %}
    <div>
      {% set dts = modules.get('FacebookEvents').getDates(event) %}
      <a href="https://www.facebook.com/events/{{event.id}}/" title="Facebook">{{dts.dates}}:</a>
      {{event.name}} <em>{{dts.times}}</em>
    </div>
  {% endif %}
{% endfor %
20 people like this

Share this post


Link to post
Share on other sites

At the moment the endpoint just returns: id, name, timezone, start_time, end_time, description.

But it's pretty easy to get the information about the place and cover. I updated the module to include it as well and updated the Graph Api Version to 2.9.

`$modules->get('FacebookEvents')->getEvents()` returns now the following data:

array(1) {
  [0]=>
  array(6) {
    ["id"]=>
    string(15) "123123123"
    ["name"]=>
    string(3) "xxx"
    ["timezone"]=>
    string(13) "Europe/Berlin"
    ["start_time"]=>
    string(24) "2017-06-23T16:00:00+0200"
    ["end_time"]=>
    string(24) "2017-06-23T18:30:00+0200"
    ["description"]=>
    string(3) "foo",
    ["place"]=>
    array(3) {
      ["name"]=>
      string(5) "Venue"
      ["location"]=>
      array(6) {
        ["city"]=>
        string(7) "Berlin"
        ["country"]=>
        string(7) "Germany"
        ["latitude"]=>
        float(xx.3321915)
        ["longitude"]=>
        float(xx.3735704)
        ["street"]=>
        string(17) "Street 14"
        ["zip"]=>
        string(5) "01234"
      }
      ["id"]=>
      string(15) "123123123"
    }
    ["cover"]=>
    array(4) {
      ["offset_x"]=>
      int(0)
      ["offset_y"]=>
      int(85)
      ["source"]=>
      string(148) "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/..."
      ["id"]=>
      string(16) "123123123"
    }
  }
}

 

Having a quick look at the Graph API documentation, using the event ID one could send another request to get even more data. 
Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api/reference/event/.

2 people like this

Share this post


Link to post
Share on other sites

ok thx justb3a
i'll try that.

could you help me with outputing the dates. i'm a php-beginner and can't output the events. your code above is written in twig, is that an engine?
anyway i tried it like this:

<?php
	$events = $modules->get('FacebookEvents')->getEvents();
		echo "<ul>";
			foreach($events as $event) {
				echo "<li>$event->name</li>";
				}
		echo "</ul>";
?>

but i don't get any ouput from this.
 

maybe i did something wrong while creating the facebook-app. i added the ID and SECRET into the module and the page-name. but the module doesnt add the page-ID automatically!
do i have to be the owner of the facebook-page which events i want to get?

Share this post


Link to post
Share on other sites

The workflow is as follows:

  1. Enter Client ID and Secret
  2. Enter Page Name OR Page ID: If you enter the Page Name, make sure to copy it from the Facebook page url similar to `https://www.facebook.com/NameWithoutSpaces` => NameWithoutSpaces would be the Page Name
  3. Add `$events = $modules->get('FacebookEvents')->getEvents();` to a template and open the belonging page (frontend)
  4. Go back to module settings and check (reload before) if a page id has been added. If not, your page name could not be resolved.
  5. Now you should be able to receive events:
$events = $modules->get('FacebookEvents')->getEvents();
echo "<ul>";
foreach ($events as $event) {
  echo "<li>{$event['name']}</li>";
}
echo "</ul>";

$events is an array, so you have to use the following syntax: `$event['propertyName']`.

I found a little bug and updated the module, so please make sure to get the latest version.

2 people like this

Share this post


Link to post
Share on other sites
3 hours ago, justb3a said:

$events is an array, so you have to use the following syntax: `$event['propertyName']`.

that was it!

thx, great module!
there should be a „buy-me-a-beer“-button (flattr, paypal, …)!

Share this post


Link to post
Share on other sites

me again,

everything worked fine. at first the cache was set to now. then i changed that to daily and moved the website to another directory. since then module doesn't get newly added events. it seems the old data is stored somewhere an no updates are possible.

i created a new app and tried it different APP-ID and had no luck.
i still get data output when the APP-ID, APP-SECRET and Facebook-Name-Fields are empty !? and i don't use any other cache-modules

am i doing something wrong?

Share this post


Link to post
Share on other sites

Have a look at your caches table. Search for name=Module.FacebookEvents. Delete this row.

Furthermore you could have a look at your modules table where class=FacebookEvents, column: data. 

1 person likes this

Share this post


Link to post
Share on other sites

it suddenly works now, i think the 24h were over since the last update.

i'll have look at the tables next time. thx

Share this post


Link to post
Share on other sites

ah

changed line:29 in FacebookEvents.module to:

const FB_PAGEEVENTS_URL = '%sv%s/%s/events/?fields=%s&access_token=%s&since=%s&until=%s&limit=50';

 

Share this post


Link to post
Share on other sites

Hi,

this is all working fine for me, nice module!

I have one question: is it also possible to display the image of the event?

I think i should use "Cover"  and "Source" but i'm not that good with php so I don't know in what sentence to use it..

Share this post


Link to post
Share on other sites

@ngrmm It's never a good idea to override somehing in the core or in a third-party module because if you update it your changes are overritten again. I updated the module and added an option in module settings to set the limit.

@Tacolombardi

<?php $events = $modules->get('FacebookEvents')->getEvents(); ?>
<ul>
  <?php foreach ($events as $event): ?>
    <li>
      <?=$event['name']?>
      <img src="<?=$event['cover']['source']?>" alt="<?=$event['name']?>" />
    </li>
  <?php endforeach; ?>
</ul>

 

2 people like this

Share this post


Link to post
Share on other sites
On 1.6.2017 at 8:32 AM, justb3a said:

Have a look at your caches table. Search for name=Module.FacebookEvents. Delete this row.

Furthermore you could have a look at your modules table where class=FacebookEvents, column: data. 

still having problems. newly added events won't show up in frontend. i guess this has something to do with cache/tables.
i have to delete it manually, is there a way the module would do that automatically?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend