Facebook FQL bug
SELECT eid, start_time, name FROM event WHERE (eid IN (SELECT eid FROM event_member WHERE (uid = me() AND start_time < 1317006752)))
This FQL query is supposed to return events that began before 1317006752
However, it returns valid events IN ADDITION to this one
{
"eid": 239526399426862,
"start_time": 1317448800,
"name": "Nick Grimshaw, The 2 Bears, S.C.U.M. & more! Friday 30th Sept, Only £4.50"
}
Now correct me if I'开发者_如何学JAVAm wrong, but 1317448800
is bigger than 1317006752
.
You might be able to verify this by going to the event page, click on something (i.e not attend), then run the query here
I think your issue might be the difference in timezone between the event creator and the active user. Facebook provides this notice:
Note that the start_time and end_time are the times that were inputted by the event creator. Facebook Events have no concept of timezone, so, in general, you can should not treat the value returned as occurring at any particular absolute time. When an event is displayed on facebook, no timezone is specified or implied.
Apparently start_time in event_member is used purely to speed up queries on event_member table which can return many results. Seems like it is not updated when the event's start_time is updated. Your query should be like the following to work properly, note the difference:
SELECT eid, start_time, name
FROM event
WHERE eid IN (SELECT eid
FROM event_member
WHERE uid = me() AND start_time < 1317006752)
AND start_time < 1317006752
I agree this is a bug though.
I had this problem today getting upcoming events : The correct FQL should be
SELECT eid,name,description,location,start_time,end_time,pic_big FROM event WHERE eid IN (SELECT eid FROM event_member WHERE start_time>=PLACE_UNIX_TIMESTAMP AND uid=PLACE_UID_HERE) ORDER BY start_time ASC
EDIT
Fetching the result of this query is done by :
$sql = '/fql?q=SELECT+eid,name,description,location,start_time,end_time,pic_big+FROM+event+WHERE+eid+IN+(SELECT+eid+FROM+event_member+WHERE+start_time>={time}+AND+uid={id})+ORDER+BY+start_time+ASC';
$fql_query_result = file_get_contents('https://graph.facebook.com/' . $sql '&access_token={token}');
$data = json_decode($fql_query_result,true, 512, JSON_BIGINT_AS_STRING));
Important to add the JSON_BIGINT_AS_STRING option to the json_decode to prevent the eid of becoming a shortend float representation
EDIT 2: As the const JSON_BIG... is only available from php5.4.X+ :
if (defined('JON_BIGINT_AS_STRING')) return json_decode($fql_query_result,true, 512, JSON_BIGINT_AS_STRING);
return json_decode(preg_replace('/([^\\\])":([0-9]{10,})(,|})/', '$1":"$2"$3', $fql_query_result),true);
source : http://www.pixelastic.com/blog/321:fix-floating-issue-json-decode-php-5-3
精彩评论