Her'es the situation, I run the following FQL code (in the debugger currently) to search my stream for specific items:
SELECT attachment,description,message
FROM stream
WHERE
(source_id=me())
AND
strpos(message,'shakshuka') >=0
Things are alright - I get results, woohoo.
BUT (!) :
When I change the condition, to something that should be very simple-
to support also my friends posts, suddenly.. I get nothing.
For example:
SELECT attachment,description,message
FROM stream
WHERE
(source_id IN (SELECT uid2 FROM friend WHERE uid1 = me()) OR source_id=me())
AND
strpos(message,'shakshuka') >=0
I could run these twice but... why?!
I don't want to.
There's something wrong with all considering limitations and FQL queries, after reading some posts # FB dev forums,
I just added LIMIT 500 OFFSET 0 to the end of the query and it works like magic.
I guess the tech guys # Facebook need a little extra hand in all regarding to stable their own "SQL" version.
Related
I'm using FQL to get comment data from webpage with a Facebook comment box. I use the graph to get the object_id, then use FQL to get all comments with that object_id. However, if I want to pull data from a specific comment using its id (sometimes referred to as an XID) the FQL returns 0 results.
According to https://developers.facebook.com/docs/reference/fql/comment/ the id should be indexed, so this query should work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id={some known XID}
But it doesn't. BTW, THIS query does work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+object_id={some known object_id}
It is irritating how I can't pull query for comments using time or fromid or anything other than object_id, id, post_id, and parent_id... but in practice only using the object_id returns anything.
has anyone else run into this problem? Is my XID query wrong somehow, or is the id only indexed on certain kinds of comments, and not webpage comments for no inexplicable reason?
This one I managed to solve with trial and error. I had to put the id in single quotes. It's odd, I could query the object_id without putting it in quotes, but not the id. This is sort of what the working FQL looked like, except with a valid access token:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id='#########_####'
as opposed to:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id=#########_####
which failed to return any results.
Thanks for being consistent, Facebook :(
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.
We are encountering an issue during the current Hackathon in my company. We access to our newsfeed through the FQL.
When we try to access to some old (but not so much!) informations, we are confronted to a problem: sometimes we have some datas returned, sometimes not.
That's a big deal for us cause it makes our project non reliable.
Example:
fql?q=select source_id, message, attachment, created_time from stream where filter_key="nf" AND created_time < 1323648660
Sometimes returns:
{
"data": [
]
}
Sometimes returns a list a 25 datas as expected.
Look like a wrong cache management?
Is this an open bug for FB ? It's kind of critical.
Hope you will be able to help me,
Regards,
François JAGUELIN
Limit the source_id to one user, for example:
fql?q=select source_id, message, attachment, created_time from stream where filter_key="nf" AND created_time < 1323648660 AND source_id = XXXX
When you don't limit the source_id to one user, the time you query over is greatly reduced. If you need to query over multiple source_id's, pack single source_id queries into a multiquery.
From FbDevWiki...
*The stream table is really two concepts built into one table. If you specify a filter_key and/or multiple users, the results will behave like the stream in Facebook's home page. If only one user is specified, and no filter_key is specified, the table will assume that you want a profile-like view, and all that implies.
Those behaviors differ significantly. For example, the homepage-like view only aggregates data over the last few days. The profile-like view gets much older data from our databases.*
In Facebook query language(FQL), you can specify an IN clause, like:
SELECT uid1, uid2 FROM friend WHERE uid1 IN (1000, 1001, 1002)
Does anyone know what's the maximum number of parameters you can pass into IN?
I think the maximum result set size is 5000
It may seem like an odd number (so perhaps I miss counted, but it's close ~1), but I can not seem to query more than 73 IN items. This is my query:
SELECT object_id, metric, value
FROM insights
WHERE object_id IN ( ~73 PAGE IDS HERE~ )
AND metric='page_fans'
AND end_time=end_time_date('2011-06-04')
AND period=period('lifetime')
This is using the JavaSCript FB.api() call.
Not sure if there is an undocumented limit or it might be an issue of facebook fql server timeout.
You should check if there is a error 500 returned from FB web server which might indicate you are passing a too long GET statement (see Facebook query language - long query)
I realized my get was too long so instead of putting many numbers in the IN statement, i put a sub-query there that fetches those numbers from FB FQL - but unfortunately it looks like FB couldn't handle the query and returned an 'unknown error' in the JSON which really doesn't help us understand the problem.
There shoud not be a maximum number of parameters as there isnt in SQL IN as far as I know.
http://www.sql-tutorial.net/SQL-IN.asp
just dont use more parameters than you have values for the function to check because you will not get any results (dont know if it will give away an error as I never tried to).
I am trying to write a Facebook query that will return all comments posted by a user to his friends,
however I can't seem to find the correct schema. Its as if there are no 'indexable' fields to build this.
Any suggestions please?
With thanks,
Wineshtain
The indirect path for stream comments would be something like
select * from comments where fromid = <my_id> and object_id in (
select post_id from stream where sourceid in (
select uid1 from friend where uid2 = <my_id> ) )
for photos, substitute the middle query with
SELECT pid FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner IN ( ...
Unfortunately the security settings may restrict the querying your friends wall posts and photos.
I don't believe you can accomplish this in a direct manner as you describe. FQL tables are generally only indexed on a limited criteria (for performance reasons I'm sure). In the case of the Comments FQL Table, you can only select comments via a post ID or an xid.
Unfortunately, this means that you have to know the objects that a user has commented on before you can get the comments for it. You would have to have previously selected all the posts, photos, etc. that you wished to get the comments for before you could retrieve them.