Jump to content

Facebook Events


justb3a
 Share

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
Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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?

Link to comment
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
Link to comment
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, …)!

Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
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
Link to comment
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..

Link to comment
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
Link to comment
Share on other sites

  • 3 weeks later...
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?

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 2 weeks later...
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
Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
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
Link to comment
Share on other sites

  • 5 months later...

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
 Share

×
×
  • Create New...