Giter Club home page Giter Club logo

facebook-events-by-location-core's Introduction

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

  • The Graph API has some "instabilities" with search results. It's possible that the amount of results returned can vary between calls within seconds
  • The /search endpoint "magically" limits the number of results, independent from the distance used (larger distance doesn't guarantee more results)
  • Rate limiting will apply, but I experienced no call blocks within a reasonable amount of service requests. Be aware that the way this application works, there are potentially hundreds of (counted) Graph API calls per request to /events.

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:

  • lat: The latitude of the position/coordinate the events shall be returned for
  • lng: The longitude of the position/coordinate the events shall be returned for

Non-mandatory parameters

  • query: The term(s) on which you want to narrow down your location search (this only filters the places, not the events itself!).
  • limit: Limits the number of results in your location search (this only limits the places, not the events!). Default is 100. This can be used to speed up response time if you don't want to retrieve the maximum number of events.
  • categories: The array of place categories that should be searched for. Valid entries are ARTS_ENTERTAINMENT, EDUCATION, FITNESS_RECREATION, FOOD_BEVERAGE, HOTEL_LODGING, MEDICAL_HEALTH, SHOPPING_RETAIL, TRAVEL_TRANSPORTATION. Default is none.
  • accessToken: The App Access Token to be used for the requests to the Graph API.
  • distance: The distance in meters (it makes sense to use smaller distances, like max. 2500). Default is 100.
  • sort: The results can be sorted by time, distance (legacy option, will be removed in future release), venueDistance, eventDistance, venue or popularity. If omitted, the events will be returned in the order they were received from the Graph API.
  • version: The version of the Graph API to use. Default is v2.10.
  • since: The start of the range to filter results. Format is Unix timestamp or strtotime data value, as accepted by FB Graph API.
  • until: The end of the range to filter results.
  • showActiveOnly: Whether only non-cancelled, non-draft Events should be shown. Format is boolean. Default is true.

Location/Place data in the query result

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

  • place: This is the consolidated Place object from the Venue (which is actually the Page object which was returned from the Place search), and the Event's place data. The latter will supersede the Place page data.
  • venue.location: This is the location data of the Page object.

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:

  • If you want consistency regarding query vs. results, you should use venue.location.
  • If you want accuracy regarding the real event location, you should use place.

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": "[email protected]",
      "emails": ["[email protected]"],
      "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
  }
}

facebook-events-by-location-core's People

Contributors

arjunlol avatar pbadeer avatar razekteixeira avatar renatopster avatar stoto98 avatar tobilg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facebook-events-by-location-core's Issues

Add option to specify limit

I'd love the ability to specify a limit of the amount of events that I get back from the search. Is this something I could propose as a pull request?

Can i use this?

Hi,

I need to fetch some events containing a keyword (eg. cars) inside a radius.
(i'd get events all over the world)
Google discover can do this quite smartly, but i still haven't seen another solution.

Is this - api heavy - hack the ONLY way to accomplish this still?
I'm guessing this is exactly as i need.

Error on newest version

Hey, first of all thanks for keeping this awesome piece of software updated!!

I upgraded to the newest version today (0.3.0), but it's throwing some errors when I try to do a request

Warning: a promise was rejected with a non-error: [object Object] W20170413-18:18:15.252(2)? (STDERR) at /Users/projects/Projects/Personal/node_modules/facebook-events-by-location-core/lib/eventSearch.js:325:17 W20170413-18:18:15.252(2)? (STDERR) at processImmediate [as _immediateCallback] (timers.js:396:17) W20170413-18:18:15.253(2)? (STDERR) From previous event: W20170413-18:18:15.253(2)? (STDERR) at [object Object].EventSearch.search (/Users/projects/Projects/Personal/node_modules/facebook-events-by-location-core/lib/eventSearch.js:131:12) W20170413-18:18:15.253(2)? (STDERR) at [object Object]._handler (imports/server/publish.js:30:8) W20170413-18:18:15.253(2)? (STDERR) at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1737:12) W20170413-18:18:15.253(2)? (STDERR) at [object Object]._.extend._runHandler (packages/ddp-server/livedata_server.js:1035:17) W20170413-18:18:15.262(2)? (STDERR) at [object Object]._.extend._startSubscription (packages/ddp-server/livedata_server.js:853:9) W20170413-18:18:15.263(2)? (STDERR) at [object Object]._.extend.protocol_handlers.sub (packages/ddp-server/livedata_server.js:625:12) W20170413-18:18:15.263(2)? (STDERR) at packages/ddp-server/livedata_server.js:559:43 W20170413-18:18:15.380(2)? (STDERR) {"message":{"name":"StatusCodeError","statusCode":400,"message":"400 - \"{\\\"error\\\":{\\\"message\\\":\\\"The action attempted has been deemed abusive or is otherwise disallow ed\\\",\\\"type\\\":\\\"OAuthException\\\",\\\"code\\\":368,\\\"error_subcode\\\":1489009,\\\"is_transient\\\":false,\\\"error_user_title\\\":\\\"Too many place searches\\\",\\\"error_user_msg\\\":\\\"You searched for too many places in a short amount of time. You will be allowed to search for more places after some time has passed.\\\",\\\"fbtrace_id\\\":\\\"FIj9mmbDdYI\\\"}}\"","error":"{\"error\":{\"message\":\"The action attempted has been deemed abusive or is otherwise disallowed\",\"type\":\"OAuthException\",\"code\":368,\"error_subcode\":1489009,\"is_transient\":false,\"error_user_title\":\"Too many place searches\",\"error_use r_msg\":\"You searched for too many places in a short amount of time. You will be allowed to search for more places after some time has passed.\",\"fbtrace_id\":\"FIj9mmbDdYI\"}}","options":{"uri":"https://graph.fa cebook.com/v2.7/search?type=place&q=&center=52.370987900020594,4.897470250725746&distance=1000&limit=100&fields=id&access_token=EAAZAEZC5u8GuoBAJR2kevJwwWIXw2ZBY1lTdoK7XIqE4BLm61w6PUvoF5fhCzu35ZAZBQoogtN0QmBNjXdxQG oUZBpsv5kKNhLyvvlknaYQira3fpJGDpyfibOmHxTU32ScVJGtmJqZBsfgnnpOJ7Q63r29zZCkjsgZCCjyrTgNdgEAZDZD&after=NDk5","method":"GET","simple":true,"resolveWithFullResponse":false,"transform2xxOnly":false},"response":{"statusC ode":400,"body":"{\"error\":{\"message\":\"The action attempted has been deemed abusive or is otherwise disallowed\",\"type\":\"OAuthException\",\"code\":368,\"error_subcode\":1489009,\"is_transient\":false,\"error _user_title\":\"Too many place searches\",\"error_user_msg\":\"You searched for too many places in a short amount of time. You will be allowed to search for more places after some time has passed.\",\"fbtrace_id\": \"FIj9mmbDdYI\"}}","headers":{"www-authenticate":"OAuth \"Facebook Platform\" \"invalid_request\" \"The action attempted has been deemed abusive or is otherwise disallowed\"","access-control-allow-origin":"*","prag ma":"no-cache","cache-control":"no-store","x-fb-rev":"2955911","content-type":"text/javascript; charset=UTF-8","x-fb-trace-id":"FIj9mmbDdYI","facebook-api-version":"v2.7","expires":"Sat, 01 Jan 2000 00:00:00 GMT"," vary":"Accept-Encoding","x-fb-debug":"KG8CEACPNSrtXex5Bj5wG37UAGfLD2bJJQw1Oyn0/pPD6t0JpL7iNVi6JnYyWa82PKPejDA1hikGahGUHweBXw==","date":"Thu, 13 Apr 2017 16:18:14 GMT","connection":"close"},"request":{"uri":{"protoc ol":"https:","slashes":true,"auth":null,"host":"graph.facebook.com","port":443,"hostname":"graph.facebook.com","hash":null,"search":"?type=place&q=&center=52.370987900020594,4.897470250725746&distance=1000&limit=10 0&fields=id&access_token=EAAZAEZC5u8GuoBAJR2kevJwwWIXw2ZBY1lTdoK7XIqE4BLm61w6PUvoF5fhCzu35ZAZBQoogtN0QmBNjXdxQGoUZBpsv5kKNhLyvvlknaYQira3fpJGDpyfibOmHxTU32ScVJGtmJqZBsfgnnpOJ7Q63r29zZCkjsgZCCjyrTgNdgEAZDZD&after=ND k5","query":"type=place&q=&center=52.370987900020594,4.897470250725746&distance=1000&limit=100&fields=id&access_token=EAAZAEZC5u8GuoBAJR2kevJwwWIXw2ZBY1lTdoK7XIqE4BLm61w6PUvoF5fhCzu35ZAZBQoogtN0QmBNjXdxQGoUZBpsv5kK NhLyvvlknaYQira3fpJGDpyfibOmHxTU32ScVJGtmJqZBsfgnnpOJ7Q63r29zZCkjsgZCCjyrTgNdgEAZDZD&after=NDk5","pathname":"/v2.7/search","path":"/v2.7/search?type=place&q=&center=52.370987900020594,4.897470250725746&distance=100 0&limit=100&fields=id&access_token=EAAZAEZC5u8GuoBAJR2kevJwwWIXw2ZBY1lTdoK7XIqE4BLm61w6PUvoF5fhCzu35ZAZBQoogtN0QmBNjXdxQGoUZBpsv5kKNhLyvvlknaYQira3fpJGDpyfibOmHxTU32ScVJGtmJqZBsfgnnpOJ7Q63r29zZCkjsgZCCjyrTgNdgEAZDZ D&after=NDk5","href":"https://graph.facebook.com/v2.7/search?type=place&q=&center=52.370987900020594,4.897470250725746&distance=1000&limit=100&fields=id&access_token=EAAZAEZC5u8GuoBAJR2kevJwwWIXw2ZBY1lTdoK7XIqE4BLm 61w6PUvoF5fhCzu35ZAZBQoogtN0QmBNjXdxQGoUZBpsv5kKNhLyvvlknaYQira3fpJGDpyfibOmHxTU32ScVJGtmJqZBsfgnnpOJ7Q63r29zZCkjsgZCCjyrTgNdgEAZDZD&after=NDk5"},"method":"GET","headers":{}}}},"code":-1}

"You searched
for too many places in a short amount of time. You will be allowed to search for more places after some time has passed."

The wierd thing is that I get this after making one single request.

handling paged event table

Hi.

I was checking the following venue: ProgresjaMusicZone?fields=events

When you look at the returned output you can see:

"paging": {
 "cursors": {
   "before": "OTM4NzAzMjI2MjY1NTM2",
   "after": "MTI0ODM3NzE0NTI1NjY0MwZDZD"
 },
 "next": "https://graph.facebook.com/v2.9/142450042462794/events?access_token=XXX&pretty=0&limit=25&after=MTI0ODM3NzE0NTI1NjY0MwZDZD"

I think the current version of the script doesn't support paging of the events (it does support paging of the venues thou). I think it can be handled in two ways - by adding paging support to update the events section of the venue in case it is pages or more simple way (yet less elegant) -> add a .limit(500) while querying for the events.

Best regards,
DP.

TypeError: Converting circular structure to JSON

I'm getting this error with the following syntax. Anyone know if I've messed something up?

es.search({
lat: 59.831834,
lng: 17.635795,
accessToken: //accessToken
})
.then((events) => {
console.log(JSON.stringify(events));
})
.catch((err) => {
console.error(JSON.stringify(err));
});

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Converting circular structure to JSON

OAuthException Error on Deployment

This api works just fine for me when testing on my local machine, however it fails when I run it on a remote heroku server
Error msg from logs: {"message":{"name":"StatusCodeError","statusCode":500,"message":"500 - \"{\\\"error\\\":{\\\"message\\\":\\\"An unknown error has occurred.\\\",\\\"type\\\":\\\"OAuthException\\\",\\\"code\\\":1,\\\"fbtrace_id\\\":\\\"BHzu820eh4d\\\"}}
I checked my app access token here https://developers.facebook.com/tools/debug/accesstoken/ and it's valid. Appreciate any insight

Empty data at any coordinate

Since a few days ago, no events is being found in any coordinate. As you can see, in this request:

{ data:
   { events: [],
     metadata: { venues: 168, venuesWithEvents: 0, events: 0 }
   }
}

I'm not sure if this lib needs an update or if the Facebook politics has changed. There is no error, no exceptions. Only empty results.

Has anyone noticed?

invalid_request Syntax error

'www-authenticate': 'OAuth "Facebook Platform" "invalid_request" "Syntax error \\"Expected \\")\\", got end of string\\" at character 493: id,name,about,emails,cover.fields(id,source),picture.type(large),category,category_list.fields(name),location{city,country,latitude,longitude,state,street,zip},events.fields(id,type,name,cover.fields(id,source),picture.type(large),description,start_time,end_time,category,ticket_uri,ticketing_privacy_uri,ticketing_terms_uri,place.fields(id,name,location{city,country,latitude,longitude,state,street,zip}),is_canceled,timezone,updated_time).since(2018-04-06T18:00:00).until(2018-05-06T07:00:00"'

Has Facebook discontinued event listing api for places?

I can't get this module to return events and I can't get Facebook's graph API to return either. As I see Facebook has closed events listing down or limited it severely.

Is there anybody that can confirm this?

I wanted to make a simple event listing page where you could see local events in your city on a map without having to use Facebook directly.

Request failed with status code 400

Everything is fine, i changed anything and start getting this error

Request failed with status code 400
    at createError (.../node_modules/axios/lib/core/createError.js:16:15)
    at settle (.../node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (.../node_modules/axios/lib/adapters/http.js:192:11)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

i think could be some return that has changed in the graph api

Finding issues while trying to run the code using gulp test in terminal

I find two issues when trying to run
In the self.allowedSorts array there is no wrongSortOption
so below condition is throwing error
if (queryOptions.sort && self.allowedSorts.indexOf(queryOptions.sort) === -1) {

1)"error{"message":"An invalid sort option was passed: 'wrongSortOption'","code":3}"

and also queryOptions.longitude I am getting a null value for longitude.
2)The error is {"message":"Please specify the lat and lng parameters!","code":1}

Tutorial

Hi there
I,m very intersted on this code, can you explain how to integrate it in a php file and how to retrieve the json output ? Or can I hire you for to do that? Thank's.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.