FQL query,is possible to get all events in your area? - facebook

Talking aout Facebook FQL,
is it possible to do a query like
SELECT name, venue, location, start_time FROM event
WHERE location ="New York"
to search all public events, posted on Facebook, and available in your area?

No, since non of fields you listed are indexable
You can however search Graph API for public events in specified time ranges.
Which probably not suitable for your needs, since location field in results still not always contain reliable data, and filtering all the public events in specified range may be overkill...

Related

Convert Facebook New Search to Graph or FQL

I want to convert this request
https://www.facebook.com/search/110970792260960/events-near/
to a request that I can use with Facebook SDK, for example:
https://graph.facebook.com/fql?access_token=X&q=SELECT ....
or
search?type=event&center=Y&distance=Z
I've tried a FQL like this, unfortunately this query only return events WITH pages associated. I've tried filter the latitude and longitude from venue struct of Event but again I need to specify the ?q= parameter which reduces my results.
For the second option I can't because parameters center and distance doesn't work with type=event.
FQL is deprecated and can only be used in older Apps, but you can use the search endpoint of the Graph API to search for events: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#search
Afaik this does NOT allow you to search for events in a specific area though. That´s just not possible with the API.
As #luschn said, FQL is deprecated and can be used until August 2016. There by theory a way to query for Page Events like this:
select
eid,
name,
description,
location,
all_members_count,
attending_count,
unsure_count,
not_replied_count,
declined_count,
start_time,
end_time,
venue
from
event
where
creator in (
select
page_id
from
place
where
distance(latitude, longitude, "37.76", "-122.427") < 1000
)
and
start_time > "2015-05-22"
This only would include those events which have been created by a Page itself, and if the Page has an address stored. You can't get those Events created by Users, because you can't access their location field.

Facebook Graph API Get All Events For Latitude and Longitude

I'm trying to get All public events for given location. Here is what I'm using now
SELECT+name,+pic_cover,start_time,+end_time,+location,+description,venue++FROM+event+WHERE+eid++in(SELECT+eid+FROM+event_member+WHERE+uid+IN+(SELECT+page_id+FROM+place+WHERE+distance(latitude,+longitude,+"40.1811",+"44.5136")+<+50000+limit+0,15000))+ORDER+BY+start_time+desc+limit+0,1500
But there are huge count of events with that location which didn't returning with that FQL query.
Is there any chance to get all events for given location or it may be by City ?
I'm using Python , but if you have some example code on any language please write it out.
I think if you omit the subquery for the event_member table, you'll eventually get more results. Please consider that the results will only include Events created by the Page itself, not those created by individual users.
SELECT name, pic_cover,start_time, end_time, location, description,venue FROM event WHERE creator IN (SELECT page_id FROM place WHERE distance(latitude, longitude, "40.1811", "44.5136") < 50000 limit 0,15000) and start_time > now() ORDER BY start_time desc limit 0,1500
If you have a list of venues of interest, you could use the method I described here: Facebook FQL find all events that take place at a certain venue
Edit 2017-12-20:
As it is now impossible to use FQL if the app was created after 2014-04-30, a direct search is no longer possible. To achieve that, a three-step approach must be used, as implemented in https://github.com/tobilg/facebook-events-by-location-core for example.

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
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
I'm wrestling with this same problem right now. It does not look possible. There are several problems I see:
the location fields are not searchable in the page or place tables,
the way event locations are populated is inconsistent: See this page's events for an example. (I personally populated most of these. These are FB changes, not user error.),
FQL does not have an AS statement to query based on the result of a calculation, and
Facebook limits the amount of items returned by a query to some fairly low value.
What the referenced site seems to do is query event.description for the presence of the input string. Query "IKEA", and you'll get lots of results. Definitely not a geo search. (BTW, the site's source code is on GitHub).
Edit:
Okay, I was wrong. Facebook does expose a search method, but only in the Graph API. Using the batch request functionality, you could execute a series of requests that:
Find all place entries within a distance (in meters) of a known lat/long. The graph api accepts q=* for the search string to return all places.
Query event to find all events at the places returned above.
I'm going to play with this. I'll update this post again as I flesh out this code better.
try this code worked for me returns all details of the upcoming public event which contains a specific key word that can be your location
SELECT eid,name,description,venue,creator,location,ticket_uri,start_time, eid,host,not_replied_count,pic_square,pic_big,unsure_count,attending_count,declined_count,all_members_count FROM event WHERE start_time > now() AND CONTAINS("your location name") AND privacy='open'
I believe that in http://elmcity.info/fb_events?location=tokyo they are not really searching for events in Tokyo, they simply executing a query like this
https://graph.facebook.com/search?type=event&q=tokyo
(access token is needed, see https://developers.facebook.com/tools/explorer?method=GET&path=search%3Ftype%3Devent%26q%3Dhaifa)
Note that this url also works
http://elmcity.info/fb_events?location=sport
I'm also looking for a way to retrieve public events using fql and so far I didn't find any.

FQL, search for non-friend people and sort by mutual friends

I look for facebook users (any user, not just my friends or the friends of a specific user) with a pattern in the name, like this:
SELECT first_name,uid FROM user WHERE contains('pete')
This returns an array of people who's name contains "pete" (i.e. also "peter"). The number is quite high, so the results are of course truncated. I would like to grab, in this set (before the server-side truncation) who has most mutual friends with me (or with an arbitrary user id). However, issuing
SELECT first_name,uid FROM user WHERE contains('pete') AND mutual_friend_count > 1
gives and empty set (and no errors). I think the server truncates before applying the latter selection, as in normal SQL would happen, for performance reasons (or explicit limits I missed in the documentation).
I made a second attempt by trying to retrieve all the friends of friends of a userid, and then select on the name. However, retrieving friends of friends is not allowed (and technically difficult because some friends hide their list of friends, and this breaks the query).
I can see no other way to achieve my goal... is there any? (I mean: given a userid, search for users with highest number of mutual friends).
Your best bet, since there's no FQL solution, would be to begin a database of your own following Facebook's best practices and policies of course. That way you can structure your data. Data can be kept current by setting up Facebook's Realtime updates API (https://developers.facebook.com/docs/reference/api/realtime/) to capture when new friendships are made.
I just tried it with "order by mutual_friend_count desc" and it worked. So the query needs to be:
SELECT first_name,uid FROM user WHERE contains('pete') order by mutual_friend_count desc

Use Facebook FQL to select the work information from the profile

I would like to get work place information of a user using FQL.
When I use the Graph API and get the User object, it contains work information, which is essentially a list of the work history. The list elements contain nodes of employer, location, description, etc...
The nodes appear to be pages internally. If I take the id of a node, e.g. from the employer, and use FQL to query a page with that page_id, I do get an object with corresponding information.
My question now is, how do I use FQL to get the same information without accessing the Graph API? What table stores the work-related information, for example how do I find all the page_id of the employers of a given user?
The reason I insist on using FQL only is performance. Of course I could access the Graph API for all the users in question and get the info that way, but I'm looking for an FQL-only solution.
You can get this information from FQL. Read the "user" table and look for the work field. The JSON data returned should be the same format as the one for Graph, i.e., the result is an array and each result should include an "employer" object with an "id" and "name" field.
You will need user_work_history or friends_work_history to access this field.