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

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>"

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!

FQL multiqueries without returning everything

I'm using multi queries with FQL, I have 3 queries actually.
The third one is the one that interests me the most, however Facebook returns the result of the previous queries first, which means more overhead for me to process and more time to stream in the result. Is there a way to limit Facebook into only sending the result set of the 3rd query?
JSONqueries["query1"] = encodeURIComponent('SELECT uid1 FROM friend WHERE uid2 = me()');
JSONqueries["query2"] = encodeURIComponent('SELECT eid FROM event_member WHERE uid IN (SELECT uid1 FROM #query1)');
JSONqueries["query3"] = encodeURIComponent('SELECT eid, start_time, end_time, update_time, location, venue FROM event WHERE eid IN (SELECT eid FROM #query2) and privacy=\'OPEN\'');
Here you are. But it's still too complex and therefore extremely slow.
SELECT eid, start_time, end_time, update_time, location, venue FROM event WHERE eid IN(SELECT eid FROM event_member WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = me())) and privacy="OPEN"

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)