justb3a

Facebook Events

Recommended Posts

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 %
  • Like 21

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/.

  • Like 2

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.

  • Like 2

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. 

  • Like 1

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>

 

  • Like 3

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

What i did was to make the Page ID field editable, that was the only way to test the module with a dummy events feed and then switch it out to a different page; the clear module cache select item is not working for some reason...

in line 66 of the FacebookEventsConfig.php you can comment out this:

$field->collapsed = Inputfield::collapsedNoLocked;

fb_events1.thumb.jpg.10036a3e8744f370d4db601b86f025e6.jpg

...

:(

...

fc_events2.thumb.jpg.213dbdf62a2e2c4f176a1886a94e93af.jpg

I made some other changes to the module to allow the users to configure the since date, and until date; Once that's all stable i'll hopefully do a pull request on github for the extended features; and if i can figure out how to make it update the ID of the page if the cache is set to expire now, i'll post back here..

Share this post


Link to post
Share on other sites

@Macrura Are you using the latest version? I fixed a little bug just a few weeks ago. Looking forward to merge your PR :P

Share this post


Link to post
Share on other sites

What about this module makes to specific to PW 3.x and above? I would like to be able to use it on site using PW 2.7.2.

Share this post


Link to post
Share on other sites
15 minutes ago, Lance O. said:

What about this module makes to specific to PW 3.x and above? I would like to be able to use it on site using PW 2.7.2.

This module uses namespaces which has been introduced with PW 3. I upgraded all my projects to PW 3.x, so I have no need to test and support older versions. :) 

  • Like 1

Share this post


Link to post
Share on other sites

This may be a dumb question, but how do I get past events?

With normal usage I just get the future events, but when I modify the module at the getEvents() function and set the $sinceDate to 0, I get all past events aswell.

Am I missing an implemented solution intended by @justb3a?

Share this post


Link to post
Share on other sites

ok cool -thanks for testing out my version!

i will be submitting a PR soon so once that happens and if it is accepted you could switch back to the official branch; but if it works for you and satisfies your current requirements, it should be 'stable', there are just a few simple changes to the code and those added inputfields. if you do run into any issues, you can post an issue on the forked github issues page..

Share this post


Link to post
Share on other sites
On 28/10/2017 at 5:39 PM, Macrura said:

i will be submitting a PR soon so once that happens and if it is accepted you could switch back to the official branch; but if it works for you and satisfies your current requirements, it should be 'stable', there are just a few simple changes to the code and those added inputfields. if you do run into any issues, you can post an issue on the forked github issues page..

I created a "Pull Request" at my own and extended the module config, so one is able to define a date range and reverse sorting. Thanks @Macrura

  • Like 4

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 kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt
       
    • By teppo
      Code Blocks Textformatter is a tiny Textformatter module I cooked up to add support for code blocks to text/textarea/RTE fields on some of the sites I work with. Unlike a full-blown Markdown Textformatter – which is something that we already have in the core – this module simply adds support for fenced and inline code blocks.
      The syntax is based on the GitHub code block documentation, so please refer to that for additional instructions. The README at GitHub also includes some basic examples. As with any Textformatter, in order to enable this one, install it and enable it via field settings. Note that there's no syntax highlighting built in (at least for the time being), so use a tool of your choice for that – personally I prefer Prism.js.
      Since this module doesn't use a Markdown tool behind the scenes, but rather some home baked regular expressions, there's always the possibility that I've missed something – but please let me know if you use this module and run into any issues. On the other hand this module should be relatively fast and unobtrusive, as there are no unnecessary bits of code to run 
      GitHub repository: https://github.com/teppokoivula/TextformatterCodeBlocks Modules directory: http://modules.processwire.com/modules/textformatter-code-blocks/
    • By theo
      Here is my first processwire module (beta).
      https://github.com/theo222/ImagePickerField
      A lot of "first times". First time Github, Markdown and of course PW Modules.
      So be gentle please.
      I hope it works.

    • By horst
      Image Animated GIF  v 2.0.2
       
      Module for PW 2.5 stable or newer, but is obsolete for PW Versions greater then 3.0.89 (... read more ...)
       
      This module helps with resizing and cropping of animated GIFs when using the GD-Library.
      The GD-Library does not support this.


      This module is completely based upon the fantastic work of

         László Zsidi (http://www.gifs.hu/, builts the initial classes)
         xurei (https://github.com/xurei/GIFDecoder_optimized, enhanced the classes)


      I have ported it to a PW module and it works with core imagefields, together with Pia and with CropImagefields that uses the new naming scheme since PW 2.5.
       
      ------------------------------------------------------------------------------------------------------------------------------------------
      read more in this post about the rewrite from version 1.0.0 to version 2.0.0
      ------------------------------------------------------------------------------------------------------------------------------------------
      You can find it in the modules directory: https://modules.processwire.com/modules/image-animated-gif/
      and on Github: https://github.com/horst-n/ImageAnimatedGif
      ------
      A preview can be found here