I need to retrieve among other data all the shares a person has done on his facebook account during the past year, 2012 in my case.
I found that shares are accessible via FQL table named "stream", selecting stream.type = 80. Using also the where clause on "created_time" and source_id should do the trick :
SELECT post_id,message,likes,attachment
FROM stream
WHERE source_id = me()
AND created_time > 1325397600
AND type=80
ORDER BY likes.count desc
Fact is... When querying the stream table, facebook's engine seems to need a limit. If you don't provide one, no result. I guess it's because if no limit is set, response times could be veeeery long... Anyway I'm sure they have many reasons for that. So :
SELECT post_id,message,likes,attachment
FROM stream
WHERE source_id = me()
AND created_time > 1325397600
AND type=80
ORDER BY likes.count desc
LIMIT 100
But: this limit parameter seems to be applied before some of my where clauses, unlike in SQL statements such as SQL server, it means that what fb does with my example query is sequentially :
take 100 elements from stream quite randomly, of any type (could be status, shares, photos, places, posts on your wall from friends, etc.) and any time. Actually, my source_id clause seems to be applied before limit.
then filter by type 80 and created_time, but not sure how
In my case, I need all shares from year 2012, but I can never be sure that some arbitrary limit set to 2000 or 5000 will catch all one's 2012 stream elements before applying the filter.
Maybe there is an other way ?
Thanks a lot for your help.
Related
i'm using new Facebook SDK 3.0 but it's not relevant since Graph API Explorer has the same behavior.
The problem is that when i try to fetch some user photo tags, like "me/photos" or the equivalent FQL query, i get a response of max 400 elements, using either graph or fql.
I already tried using LIMIT field (for example the FQL query is "SELECT src, src_big FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=me() LIMIT 1000) LIMIT 1000")
but nothing change.
I also tried with SINCE and UNTIL, but i understood that FB returns a table of 400 rows and then shrink it according to your query.
Is maybe another way to bypass this limit or for some unknown reason FB wanted it and it's not a bug?
Thank you
In the documentation it mention only AND and NOT.
The reason I'm trying to use OR is to break a large results sets into multiple queries and make sure the queries doesn't fail.
For example:
This query return one result:
SELECT post_id FROM stream
WHERE (source_id = '100000462790227' ) AND strpos(lower(message),'sweet') >=0
AND (filter_key = 'others')
But when I added OR on the filter key I got empty results
SELECT post_id FROM stream
WHERE (source_id = '100000462790227' ) AND strpos(lower(message),'sweet') >=0
AND (filter_key = 'others' OR filter_key = 'nf' )
Is it the OR, or do I do something else wrong?
I finally understood what is the core issue.
Stream table filter_key 'other' and 'owner' works only on one source_id.
My original query had also OR on multiple source_id something like (source_id = '100000462790227' OR source_id = '12345670' ).
This combination return empty results!!
Here are my conclusions and observations:
First "OR" is supported by FQL.
One issue I saw "Graph API explorer" fails sometime while iOS SDK calls succeeded
If you limit the call with " LIMIT X" where X is under 100 you'll get an answer also on the second query. There are few posts on the issues related to large result set and what is the right limit (the one I read are all based on trial and error).
I have a big problem with Facebook FQL, if i do
select message from stream where source_id=175102475936031
I can get the correct data, if i do this
select message from stream where source_id IN(175102475936031,etc,etc,etc)
I got a empty JSON, why? is there any alternative to this select? I have to read the messages from multiple events.
Is your problem solved?
"IN" query is a supported feature of FQL. I have tried it multiple times.
Only needs to have:
column indexable
needs to have permission to access data
data should be present for at least one column :P
select message from stream where source_id IN( 175102475936031, etc, etc, etc)
"NOT IN" is not a supported feature of FQL. Ref: http://forum.developers.facebook.net/viewtopic.php?id=1420
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).