Get profile picture creation date from user table in FQL - iphone

How can I get my friends profile pictures creation date using FQL multi-query?
I wrote below query:
SELECT src_small, src_big, src FROM photo WHERE src IN
(SELECT pic_square, pic_small, pic_big, pic FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me()) )
but it says:
{
"error": {
"message": "Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://developers.facebook.com/docs/reference/fql ",
"type": "NoIndexFunctionException",
"code": 604
}
}
Thanks in advance.

from comment by Arjuna Del Toso:
You can use a column in the WHERE clause only if it's marked as "indexable"
Not, that is not totally correct.
You need at least one indexable column in your where clause – once you have that, you can use other, non-indexed columns as well to further restrict the result.
Since the user’s current profile picture is always the album cover photo of their Profile Pictures album, we can use that to get the object_id of the profile picture of our friends, and than use that to select the info we want from the photo table:
SELECT owner, src_small, created FROM photo WHERE object_id IN (
SELECT cover_object_id FROM album WHERE owner IN (
SELECT uid1 FROM friend WHERE uid2 = me()
) AND name = 'Profile Pictures'
)

Related

FQL get last 50 photos query returns error

How can i get the last 50 photos uploaded by all my friends ?
I try to run this query in FQL:
SELECT pid, src
FROM photo
WHERE
owner IN (SELECT uid1 FROM friend WHERE uid2=me())
OR pid IN (
SELECT pid FROM photo_tag
WHERE subject in (SELECT uid1 FROM friend WHERE uid2=me())
)
ORDER BY created DESC
LIMIT 50 OFFSET 0
I need to get last 50 photos from all my friends or that my friends where tagged in...
when i run it in the API Explorer i get an error:
{
"error": "Request failed"
}
I know i have sufficen permission becus when i run these 2 query i get results:
SELECT pid, src FROM photo WHERE owner =(me())
and
SELECT uid1 FROM friend WHERE uid2=me()
EDIT:
I have also tried this ..
SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo
WHERE owner IN ( SELECT uid1 FROM friend WHERE uid2=me() )
and created >= 1377800559
ORDER BY created DESC LIMIT 100
how can i get more information ?
is it not possible to run such a query ?
Finnaly !!! Last Posted Photos from all friends...
SELECT pid, src, src_small, src_big, target_id, created, backdated_time
FROM photo where pid in (
SELECT attachment.media.photo.pid
FROM stream
WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid=me()) AND type = 247
)
as you can see my initial approach was all wrong ...
it is actually required to use the stream table to get the latest posts..
then it could be filtered to get only photos posted and use their pid to get all the required info !!! YAY!
I hope it helps other that encounter the same issue..
I'm not sure why, but a weird thing is happening here. When I tried your query- I got
Request failed
Then, after digging a bit I replaced SELECT uid2 FROM friend WHERE uid1 = me() with the IDs and the query worked!
So, as a solution you could first try to get the list of friends with :
SELECT uid2 FROM friend WHERE uid1 = me()
Then use this result in your query as-
SELECT pid, src
FROM photo
WHERE
owner IN (ID1, ID2, ID3 ...)
OR pid IN (
SELECT pid FROM photo_tag
WHERE subject IN (ID1, ID2, ID3 ...)
)
ORDER BY created DESC
LIMIT 50 OFFSET 0
Strange, but this'll work!

FQL: Selecting friend's photos

This FQL attempting to fetch photos for my friends
[1]
{"query1":"SELECT owner, object_id, src_big FROM photo
WHERE owner IN (SELECT uid2 FROM friend WHERE uid1=me())"}
provides this error response after thinking for a few seconds...
{"error_code":1,"error_msg":"An unknown error occurred"}
But this query to fetch albums for my friends will work and return a JSON object of album info
[2]
{"query1":"SELECT aid, owner, name FROM album
WHERE owner IN (SELECT uid2 FROM friend WHERE uid1=me())"}
Why does [2] work but not [1]?
Indeed, that is strange. But this one does what you want:
SELECT owner, object_id, src_big
FROM photo WHERE aid IN (
SELECT aid FROM album WHERE owner in (
SELECT uid2 FROM friend WHERE uid1=me()
)
)
Have fun with pagination!
Query [1] returns all photo objects, whereas query [2] returns album objects. The number of photos will most of the times be much larger than the number of albums. So if each friend has 10 albums each with 100 photos, the query size increases and since FQL doesn't use any form of pagination you are pulling all at once.
Consider using multi-queries in the future or batch with LIMITS

Getting friends status updates and comments using facebook api

Hi i am new in using facebook api
i want to get the friends status based on following criteria
Get all the friends details (name, uid, status_message, posted_date) whose status update has more than 15 comments/likes
following query is giving all friends status updates
SELECT status_id, uid , message FROM status WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Above query returns all my friends updates but i want to include the comments and likes on those updates in the response so that i can check the count on my side
there are comments table and likes table also in the api both might have foreign key relationship with the status_id column
Can we write a full query with joins like SQL
You can't do JOINs in FQL, but you can approximate them with a multiquery:
{
'status': 'SELECT status_id, uid , message FROM status
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())',
'comments': 'SELECT post_id, fromid, time, text FROM comment
WHERE post_id IN (SELECT status_id from #status)'
}

FQL with limit do not return results for all users

Im tryint to get the following query to return results for two of my friends:
SELECT pid, owner
FROM photo
WHERE aid IN (
SELECT aid
FROM album
WHERE owner in (
SELECT uid2
FROM friend
WHERE uid1=me()
LIMIT 0, 2 ) )
But for some reason it does only show result for one of them, and the number of rows returned is not above the limit (only about 800)
When I run:
SELECT uid2
FROM friend
WHERE uid1=me()
LIMIT 0, 2
I get a result with two friends, as expected and when I manually do a query in this form:
SELECT pid, owner
FROM photo
WHERE aid IN (
SELECT aid
FROM album
WHERE owner = USER_ID_FROM_LAST_QUERY
I get the result Id expect for both users, but Why wont it work with the IN-statement and subquery?
Edit: What I try to achieve is to get the photos of all my friends. And just asking for all photos from ALL my friends would be more then 5000 photos, and thus I cant get everything in 1 query.
Currently I got it working by doing a query for each user, to get all his pictures - and it works fine. (if you ignore the fact that it takes 2-3 minutes to execute. So I want to shorten the runtime by doing fewer queries.
Edit: more info:
With the following query i get albums from both users:
SELECT aid, owner
FROM album
WHERE owner in (
SELECT uid2
FROM friend
WHERE uid1=me()
LIMIT 0, 2 )
But with the full query, i only get pictures from albums owned by one of those users.
Try This:
SELECT pid, owner FROM photo WHERE aid IN (SELECT aid FROM album WHERE owner in (SELECT uid2 FROM friend WHERE uid1=me() LIMIT 2 ) )

Facebook FQL select 2 photos of every friends

How can I select 2 profile pictures of every friends?
I have this query:
SELECT object_id, src_small
FROM photo WHERE aid
IN ( SELECT aid FROM album WHERE owner
IN ( SELECT uid2 FROM friend WHERE uid1 = me()) AND type="profile")
That displays every profile picture of every friends. Somehow I should limit to select only 2 per user.
Any ideas?
You can use the LIMIT statement at the end of a particular query as well as ORDER BY.
So you can get their 2 latest photos by adding
ORDER BY created DESC LIMIT 2
So to get 2 from EVERY friend, you'll have to run another subquery to fetch 2 from every friend:
SELECT object_id, src_small
FROM photo WHERE pid
IN ( SELECT pid FROM photo WHERE aid
IN ( SELECT aid FROM album WHERE owner
IN ( SELECT uid2 FROM friend WHERE uid1 = me()) AND type="profile") ORDER BY created DESC LIMIT 2)