Javascript FQL: filtering by “created_time”, after a few calls (mostly 1), no results are returned
-
09-12-2019 - |
質問
I am running the following FQL query, using the javascript api:
FB.api({
method: 'fql.multiquery',
queries: {
'query1': 'SELECT source_id, actor_id, target_id, message, attachment, permalink, description, type, created_time FROM stream WHERE source_id IN (SELECT target_id FROM connection WHERE source_id=me() AND is_following=1) AND is_hidden = 0 AND type = 80 AND strpos(attachment.href, "youtu") >= 0 AND created_time < ' + unix_time,
'query2': 'SELECT uid, name, profile_url, pic_square FROM user WHERE uid IN (SELECT actor_id FROM #query1)'
}
},
function(response) {
console.log(response);
};
It's supposed to return all youtube videos on the current users feed and allow repeat querying, by supplying unix_time (on first run, this is essentially NOW()
, otherwise it's the oldest status time); which it does, buggy:
- without setting a
LIMIT
(on query1): after ~3 queries, empty results are returned LIMIT 100
or more (on query1): results are returned, but subsequent results are empty- when
created_time < NOW()
, results are returned (on multiple queries); otherwise the problem persists (created_time <
time of oldest received status )
No errors are returned. I have *read_stream* permissions. I tried to find a related bug, but found only ones about FQL not returning all statuses.
解決
API results are spotty at best. Based upon my four+ years of experience with the Facebook API I've drawn my own conclusions as to how this is happening. Here's my bullet points:
- Poor caching of data causing stale cache, cache misses, etc.
- Different web servers in the cluster not in sync with the others
- Different database servers in the cluster not keeping up with sync
- Algorithm to fetch results is admittedly "unreliable" per blog: http://developers.facebook.com/blog/post/478/ You ask for 10 and it return 7 due to pre-filtering done wrong.
I would suggest caching the data from the API on your side, and keep union'ing in new data from Facebook so your UI can present more consistent data.