tobilg / facebook-events-by-location-core

[DEPRECATED] Search Facebook events by location and proximity.
MIT License
141 stars 56 forks source link
events facebook graph-api nodejs

Search Facebook events by location, distance and search terms

Build Status GitHub forks GitHub stars GitHub license [npm]() [npm]()

Current FB issues
This package is currently no longer usable, because FB changed the way one can access the event data. It seems that access to the Events API is no longer granted, see the lengthy discussion at #29.

History
As Facebook has discontinued the FQL query API for all apps created after 2014-04-30, it has gotten much more complicated to get public Facebook events by passing a location.

Workaround
This implementation uses regular Facebook Graph API calls in a three-step approach to get the events:

  1. Search for Places in the radius of the passed coordinate and distance (/search?type=place&q={query}&center={coordinate}&distance={distance}). This returns Page objects.
  2. Use the returned Place Page objects to query for their events in parallel (/?ids={id1},{id2},{id3},...)
  3. Unify, filter and sort the results from the parallel calls and return them to the client

Known limitations

Installation

As NPM package

The module can be installed via

npm install facebook-events-by-location-core --save

Git

To clone the repository, use

git clone https://github.com/tobilg/facebook-events-by-location-core.git

Usage

The basic usage pattern of this module is the following:

var EventSearch = require("facebook-events-by-location-core");

var es = new EventSearch();

es.search({
  "lat": 40.710803,
  "lng": -73.964040
}).then(function (events) {
    console.log(JSON.stringify(events));
}).catch(function (error) {
    console.error(JSON.stringify(error));
});

Access Tokens

The above example expects that the FEBL_ACCESS_TOKEN environment variable is set to a valid App Access Token. Otherwise, you need to specify the accessToken parameter with the request.

Parameters

Mandatory parameters are the following:

Non-mandatory parameters

Location/Place data in the query result

There are two types of locations in the resulting event JSON objects:

As the Facebook Graph API can only be queried for Places via coordinate/distance, and Events can have their own, "real" location, it's possible that the place data which is found in place can be outside the boundaries of the original query.

Consequences:

Sample output (shortened)

{
  "events": [{
    "id": "836655879846811",
    "name": "U.S. Girls at Baby's All Right",
    "type": "public",
    "coverPicture": "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/24883312_1521878931228093_3223523563973203944_o.jpg?oh=9bc3e5c5d45e39c542b057b92df95243&oe=5AC0353F",
    "profilePicture": "https://scontent.xx.fbcdn.net/v/t1.0-0/c0.0.200.200/p200x200/24862268_1521878931228093_3223523563973203944_n.jpg?oh=23ec7dc943402ec7e0137f2d17f27719&oe=5AC246F8",
    "description": "Friday, April 13th @ Baby's All Right\n\nAdHoc Presents\n\nU.S. Girls\n\nTickets:  http://ticketf.ly/2j7AegO\n\n| Baby's All Right |\n146 Broadway @ Bedford Ave | Williamsburg, Brooklyn \nJMZ-Marcy, L-Bedford, G-Broadway | 8pm | $12 | 21+\n\nCheck out our calendar and sign up for our mailing list http://adhocpresents.com/",
    "startTime": "2018-04-13T20:00:00-0400",
    "endTime": null,
    "timeFromNow": 9982924,
    "isCancelled": false,
    "category": "MUSIC_EVENT",
    "ticketing": {
      "ticket_uri": "http://ticketf.ly/2j7AegO"
    },
    "place": {
      "id": "460616340718401",
      "name": "Baby's All Right",
      "location": {
        "city": "Brooklyn",
        "country": "United States",
        "latitude": 40.71012,
        "longitude": -73.96348,
        "state": "NY",
        "street": "146 Broadway",
        "zip": "11211"
      }
    },
    "distances": {
      "venue": 89,
      "event": 89
    },
    "venue": {
      "id": "460616340718401",
      "name": "Baby's All Right",
      "about": "babysallright@gmail.com",
      "emails": ["babysallright@gmail.com"],
      "coverPicture": "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/20507438_1418517768261582_7945740169309872258_o.jpg?oh=24280a4732605e140c227db955c8d5e0&oe=5AC6B878",
      "profilePicture": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/1480734_642185745894792_5820988503650852577_n.png?oh=c6e72b8a5645644e7dd3eb3d2161329f&oe=5AC0CD2D",
      "category": "Bar",
      "categoryList": ["Bar", "Breakfast & Brunch Restaurant", "Dance & Night Club"],
      "location": {
        "city": "Brooklyn",
        "country": "United States",
        "latitude": 40.71012,
        "longitude": -73.96348,
        "state": "NY",
        "street": "146 Broadway",
        "zip": "11211"
      }
    }
  }],
  "metadata": {
    "venues": 100,
    "venuesWithEvents": 2,
    "events": 25
  }
}