FQL query results in 601 Parse error: unexpected '_' - facebook-fql

Let me preface this by saying that my code seems to work for all users I've tested with but one.
I'm using the following multiquery to get a user's albums and cover image data:
{
"album_query": " SELECT aid, object_id, name, modified, size, link, cover_pid FROM album WHERE owner = me() ORDER BY modified DESC",
"cover_query": " SELECT pid, src_small, src_small_width, src_small_height FROM photo WHERE pid IN (SELECT cover_pid FROM #album_query)"
}
The query works as expected. The aid's that it returns are 100002647632588_33813 and 100002647632588_19303. Note that this is the only instance I've seen where an aid has a '_' in it.
My guess is that this is where the problem is, but moving on.
Later I run the following FQL query to get the latest 9 photos in a given album:
SELECT pid, object_id, src, src_width, src_height, src_big, src_big_width, src_big_height, modified FROM photo WHERE aid = 100002647632588_19303 ORDER BY modified DESC LIMIT 0, 9
I get the following response:
{ error_code: "601", error_msg: "Parser error: unexpected '_19303' at position 138.", ...}
This looks like a bug on facebook's end since I'm using an id that they provided, but I'm hoping a few more sets of eyes will sort me out.
Thank you for any and all help.

You need to either put "" round the aid - "100002647632588_19303" or use %22 to escape it correctly so it reads as a string and not a number -
like this -
SELECT pid, object_id, src, src_width, src_height, src_big, src_big_width, src_big_height, modified FROM photo WHERE aid = "100002647632588_19303" ORDER BY modified DESC LIMIT 0, 9
or
SELECT pid, object_id, src, src_width, src_height, src_big, src_big_width, src_big_height, modified FROM photo WHERE aid = %22100002647632588_19303%22 ORDER BY modified DESC LIMIT 0, 9

Related

FQL not returning photos tagged with friend

I am trying to use FQL to get a list of my own photos that have friends tagged in them. The friends are specified by their name or part of their name. i.e input from a text box
So far I have come up with the FQL below, which almost works, but...
Can anyone tell me why the first query returns a list of records but the second query returns nothing? the only difference between the two is the second one searches on just part of the person's name i.e "laura" vs "lau"
FQL 1
SELECT object_id, src_big, src_big_width, src_big_height, aid
FROM photo
WHERE object_id in (
SELECT object_id
FROM photo_tag
WHERE subject in (
SELECT uid
FROM user
WHERE (strpos(lower(name),"laura") >=0 )
AND (uid in (SELECT uid2 FROM friend WHERE uid1 = me()) ))
)
AND owner = me()
FQL 2
SELECT object_id, src_big, src_big_width, src_big_height, aid
FROM photo
WHERE object_id in (
SELECT object_id
FROM photo_tag
WHERE subject in (
SELECT uid
FROM user
WHERE (strpos(lower(name),"lau") >=0 )
AND (uid in (SELECT uid2 FROM friend WHERE uid1 = me()) ))
)
AND owner = me()
It looks like Facebook has a bug in its system so strpos doesn't work as expected in sub queries. As a workaround you could try splitting it into two queries - one that finds list of id-s:
SELECT uid
FROM user
WHERE (strpos(lower(name),"lau") >=0 )
AND (uid in (SELECT uid2 FROM friend WHERE uid1 = me()) )
And a second one that uses this list:
SELECT object_id, src_big, src_big_width, src_big_height, aid
FROM photo
WHERE object_id in (
SELECT object_id
FROM photo_tag
WHERE subject in (111,222,333,444,555)
)
AND owner = me()

FQL Query for getting Chat conversation

Here is the code. In the result I want to see my conversation and my friend conversation. For conversation history functionality How can I do this?
SELECT message_id, thread_id, author_id, body, created_time, viewer_id
FROM message WHERE thread_id IN
(SELECT thread_id, subject, recipients FROM thread WHERE folder_id =0 )
AND author_id = 'xxxxxxxxxxxxxxx' ORDER BY created_time DESC LIMIT 0,25
This code returns only my friend data.
You've restricted the comments returned to those authored by your friend only.
Change
AND author_id = FRIEND_ID
to
AND (author_id = FRIEND_ID OR author_id = me())
in the `WHERE clause of your query.
Get a thread_id by using your original query and then try this fql query. I think a thread_id belongs to whole conversation
SELECT message_id, thread_id,source,author_id,body,created_time,viewer_id FROM
message WHERE thread_id=THREAD_id AND (author_id=FRIEND_ID OR
author_id=me() ) ORDER BY created_time DESC LIMIT 0,25

FQL multi-query optmization for events listing

I am working on a custom Events app in Facebook and have ran into an issue where the response seems quite slow. The slowness mostly relate to trying to search for a page that is associated with an events geographical location. I.e "City, Country". Once such URL would be:
http://www.facebook.com/pages/Buenos-Aires-Argentina/106423786059675
I've already determined that it is possible to obtain the page URL for a page like this with the following FQL query:
SELECT page_id, page_url FROM page WHERE name = "Buenos Aires, Argentina" AND type = "CITY"
The type column equals CITY is important, as otherwise other non-relevant pages URLs may be returned.
Anyhow, in order to get all events by a user and display their rsvp status, display information about the venue and also get the geographic places page URL I'm running the following mult-query FQL:
[events_query] => SELECT eid, name, pic_square, start_time, end_time, location, description, all_members_count, venue FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid = 6747251459 AND start_time > 0) AND start_time > 0 AND end_time < now() ORDER BY start_time desc LIMIT 5
[rsvp_query] => SELECT eid, rsvp_status FROM event_member WHERE eid IN (SELECT eid FROM #events_query) AND uid = YOUR_EVENTS_UID
[venue_page_id_query] => SELECT page_id FROM place WHERE page_id IN (SELECT venue.id FROM #events_query)
[venue_info_query] => SELECT page_id, name, page_url, location FROM page WHERE page_id IN (SELECT page_id FROM #venue_page_id_query)
[geo_city_country_query] => SELECT name, page_url FROM page WHERE name IN (SELECT concat(location.city, ', ', location.country) FROM #venue_info_query) AND type = "CITY"
My problem is that when doing the "geo_city_country_query" the response slows down quite a bit. To approx +5seconds. Without the "geo_city_country_query" query, the response time is approx 1.5sec-2sec.
Is there any way I can get this done faster?
Thanks in advance!

Get photos from stream

Is there a way to get all of the photos form a given stream query? I tried the following but it returns an empty set.
SELECT pid, aid, src_big FROM photo WHERE pid IN (SELECT attachment.media.photo.pid FROM #feed)
Its tough to tell since I can't see your '#feed' query but more than likely you are missing a stream_filter query. This would give you something like the following 3 queries. Good Luck!
Query 'key':
SELECT filter_key
FROM stream_filter
WHERE uid = me() AND name = 'Photos'
Query 'feed':
SELECT attachment.media.photo.pid
FROM stream
WHERE source_id = {id here} AND filter_key IN (SELECT filter FROM #key)
Query 'photos':
SELECT caption, src_big, modified
FROM photo
WHERE pid IN (SELECT pid FROM #feed)

FQL statement to get a photo of two people (Query not indexable error)

SELECT pid FROM photo WHERE me() and $otherPerson IN ( SELECT subject FROM photo_tag WHERE pid=pid ) ORDER BY created DESC LIMIT 1
I'm trying to get a photo that has both users tagged in it ($otherPerson is replaced with a user id). This query returns:
604 Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://wiki.developers.facebook.com/index.php/FQL_Tables
Any ideas on how I can make this work?
UPDATE:
I currently have this query working but I feel as though there's a better way to go about.
SELECT pid, src_big FROM photo
WHERE pid IN (
SELECT pid FROM photo_tag
WHERE subject=$otherGuy
AND pid in (
SELECT pid FROM photo_tag WHERE subject=me()
)
)
This should do the trick.
SELECT pid, src_big
FROM photo
WHERE pid IN(
SELECT pid
FROM photo_tag
WHERE subject = me()
)
AND pid IN(
SELECT pid
FROM photo_tag
WHERE subject = <friend_user_id>
)
What about:
SELECT pid
FROM photo
WHERE me() IN (SELECT subject
FROM photo_tag
WHERE pid=pid)
AND $otherPerson IN (SELECT subject
FROM photo_tag
WHERE pid=pid)
ORDER BY created DESC
LIMIT 1
Also, what pid=pid means?
I tried the other solutions and ran into a problem - If your friend has set his privacy settings to disallow apps from accessing his photos, then the following FQL query will return an empty table:
"SELECT pid FROM photo_tag WHERE subject = <friend_user_id>"
I solved this by using the following multiquery instead:
"query1" : "SELECT subject, pid FROM photo_tag WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=me())"
"query2" : "SELECT pid FROM #query1 WHERE subject= <friend_user_id>"