Search code examples
facebooklocationfacebook-fqllatitude-longitudefacebook-events

FQL query for finding public event


I would like to execute an FQL query for retrieving all the public events in a specific area (using longitude,latitude and maximum distance or simply location name). Do you know if it's possible?

Apparently, somebody is able to do it, somehow: http://elmcity.info/fb_events?location=tokyo


Solution

  • It is possible indeed to receive events using location based "search" To do so you'll need the longitude and latitude coordinates of the location you want to search and a access_token with user_events permission (i think you could also use the public search)

    Here's an FQL example how can you get all the events nearby of a location. (this searches from your and your friends events):

    $lat = "40";
    $long = "30";
    
    // using offset gives us a "square" on the map from where to search the events
    $offset = 0.4;
    
    $events = 'SELECT pic_big, name, venue, location, start_time, eid FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND start_time > '. $created_time .' OR uid = me()) AND start_time > '. $created_time .' AND venue.longitude < \''. ($long+$offset) .'\' AND venue.latitude < \''. ($lat+$offset) .'\' AND venue.longitude > \''. ($long-$offset) .'\' AND venue.latitude > \''. ($lat-$offset) .'\' ORDER BY start_time ASC '. $limit;
    

    The trick itself lies in the venue.longitude and venue.latitude useage. To get events from a city, just get the city coordinates and adjust the offset to your needs. If you don't know how to use FQL please look into Facebook PHP SDK