FQL not returning photos tagged with friend - facebook

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()

Related

FQL query to get all friends events in a given city

I tried to limit to a latitude/longitude range but don't know how to do it
Here's what I've tried
SELECT name, venue, location, start_time, eid FROM event
WHERE eid IN (
SELECT eid FROM event_member
WHERE (uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) OR uid = me())
)
AND start_time > now()
AND venue.latitude < '-22.821757'
AND venue.latitude > '-23.056989'
but the coordinate comparison doensn't work because i'm comparing to a string
If I take away the quotes I get:
(#601) Parser error: unexpected '-' at position 233
https://developers.facebook.com/tools/explorer
Thanks

FQL Multiquery writing join queries

Simply put. I need help building an FQL multi query request that will do the following:
Grab the UIDs in from the logged in user's friends list then,
Use those IDs to grab all comments and messages (from stream) from the last two weeks
Finally, join those results with there usernames
Heres the queries I have so far:
[1] GRAB_UIDs:
SELECT uid2 FROM friend WHERE uid1 = me()
[2] GRAB_STREAM (missing the 2 week part and possibly wrong altogether):
SELECT type, created_time, post_id, comments, actor_id, target_id, message
FROM stream
WHERE filter_key IN
(SELECT filter_key FROM stream_filter WHERE uid = me())
AND actor_id IN
(SELECT uid2 FROM friend WHERE uid1 = me())
)';
[3] GRAB_USRNAMES:
SELECT uid, name, username, pic_square, current_location, profile_url
FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me())
I could really use a master at making these kind of requests and I greatly appreciate the help.
{
"query1":"SELECT uid2 FROM friend WHERE uid1 = me()",
"query2":"SELECT type, created_time, post_id, comments, actor_id, target_id, message FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid = me()) AND actor_id IN (SELECT uid2 FROM #query1)",
"query3":"SELECT uid, name, username, pic_square, current_location, profile_url FROM user WHERE uid IN (SELECT uid2 FROM #query1)"
}
You can also see the results from the Graph API Explorer at:
https://developers.facebook.com/tools/explorer?fql={%22query1%22%3A%22SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%22%2C%22query2%22%3A%22SELECT%20type%2C%20created_time%2C%20post_id%2C%20comments%2C%20actor_id%2C%20target_id%2C%20message%20FROM%20stream%20WHERE%20filter_key%20IN%20%28SELECT%20filter_key%20FROM%20stream_filter%20WHERE%20uid%20%3D%20me%28%29%29%20AND%20actor_id%20IN%20%28SELECT%20uid2%20FROM%20%23query1%29%22%2C%22query3%22%3A%22SELECT%20uid%2C%20name%2C%20username%2C%20pic_square%2C%20current_location%2C%20profile_url%20FROM%20user%20WHERE%20uid%20IN%20%28SELECT%20uid2%20FROM%20%23query1%29%22}

Get friend without friend app user with FQL or Graph

Now I get random 19 friend in my facebook with fql query : SELECT uid, pic_square, name FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = me() ) ORDER BY rand() limit 19, But now I don't know, how to get 19 friends not in friendappuser.
I already found anwser for my question:
SELECT uid, pic_square, name
FROM user WHERE uid IN (SELECT uid2 FROM friend
WHERE uid1 = me()) AND is_app_user = 0 ORDER BY rand() limit 19

Facebook API - FQL - How to read places where my friends were tagged

How to read places where my friends were tagged ?
I found sth like this, but this example is not working for me .
or do I have to check piece by piece
SELECT page_id, author_uid FROM location_post WHERE xxfriendIDxx IN tagged_uids ??
{
"my_friends":"SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() ORDER BY rand() LIMIT 100)",
"their_locations":"SELECT page_id, author_uid FROM location_post WHERE tagged_uids IN (SELECT uid FROM #my_friends) LIMIT 100",
"those_places": "SELECT page_id, name, location FROM page WHERE page_id IN (SELECT page_id FROM #their_locations)"
}
Thx for help!
The below query will give you all the places that your friends have been tagged.
SELECT page_id, name, location FROM page WHERE page_id IN (SELECT page_id FROM location_post
WHERE author_uid IN
(SELECT uid2 FROM friend WHERE uid1=me()))
Make sure you have enabled the friends_photos, friends_checkins and friends_status permissions.
I couldn't get any data either until I changed your their_locations sub-query to this:
SELECT page_id, author_uid FROM location_post WHERE
tagged_uids IN (SELECT uid FROM #my_friends)
OR author_uid IN (SELECT uid FROM #my_friends)
LIMIT 100
It still isn't returning some location tagged posts that I can see using /FRIEND_USERNAME/locations.
There are other friends I know who post location tagged items all the time, but their privacy settings must be inhibiting these from being returned by the API.
You need the user_tagged_places permission. API V-4
<?php
//permissions array
echo '<li> Login With Facebook</li>';
//call field
echo '<pre>' . echo $graphObject['tagged_places'] . '</pre>';
?>

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