one fql to get photo with owner name - facebook-fql

I am writing a fql as below.
fql='SELECT caption, owner, pid, src_big, created FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner IN (11111) ) LIMIT 1,5';
The problem is: how to write one fql to get the owner name also?
Thanks.

You may get owner name by joining the two tables photo and album. I am not sure how your table columns are but i suppose you must have an pid in album table so you can link tables likes this.
SELECT caption, owner, pid, src_big, created FROM photo LEFT JOIN album ON photo.pid=album.pid where aid IN (11111) LIMIT 1,5

Related

Incorrect/incomplete results from FQL

So, I need to get the most recent photos from my friends. I tried running some queries from my code as well as from the FQL explorer at http://developers.facebook.com/tools/explorer
The following query never returns.
SELECT src_big, created, owner FROM photo WHERE owner in (select uid2 from friend where uid1=me()) order by created desc
Perhaps not a good idea to use the WHERE clause on owner, even though the FQL docs do say owner is indexed. So, I modified it to:
SELECT src_big, created, owner FROM photo WHERE aid in (select aid from album where owner in (select uid2 from friend where uid1=me())) order by created desc limit 2000
and that does return but only returns photos from 3 of my friends and the total photo count is nowhere close to 2000.
I tried restricting the results to only photos created in the last 7 days.
SELECT src_big, created, owner FROM photo WHERE aid in (select aid from album where owner in (select uid2 from friend where uid1=me())) and created > 1361570941 order by created desc limit 2000
Now I get only 1 photo (obviously from 1 owner).
Then I tried the last 365 days.
SELECT src_big, created, owner FROM photo WHERE aid in (select aid from album where owner in (select uid2 from friend where uid1=me())) and created > 1330639808 order by created desc limit 2000
Now I got more photos, but still not 2000, and again only from those 3 owners.
If I now loop through each of my friends and run this query:
SELECT src_big, created, owner FROM photo WHERE owner = and created > 1330639808 order by created desc limit 100
then I get proper results, and eventually when I am done with all friends I have photos from 202 friends, and if I sort the overall result by created, those aforementioned 3 owners don't dominate the top rows. There are many owners who have posted photos in the top 2000 spots, so the previous queries are clearly returning incorrect (incomplete) data.
But the last way to do it (loop through all friends) is terrible for performance compared to the previous queries - we are talking several minutes instead of a few seconds.
Is this a known problem or limitation? Any workarounds?
A Facebook employee friend of mine suggested using multi-queries as in:
{
"p1" : "SELECT src_big, created, owner FROM photo WHERE owner = 4850 AND created > 1341203410",
"p2" : "SELECT src_big, created, owner FROM photo WHERE owner = 5569 AND created > 1341203410"
}
I haven't tried it out yet, but I am guessing it will be much faster than making an API call per friend.
He said he will file a bug on the incorrect results from my original query.

Get friends most liked photos from facebook using fql

I am trying to obtain most liked photos of my friends in 2012. I have made the following query.
SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified, like_info
FROM photo WHERE created > 1325356200 and aid
IN (SELECT aid FROM album WHERE owner
IN (SELECT uid2 FROM friend WHERE uid1=me()))
ORDER BY like_info.like_count DESC LIMIT 30
It is giving me most liked 30 photos in descending order. But when I inspected the photos I could understand that the list is not correct. Some most liked photos of my friends's is not there in list. I inspected the query many times. I couldn't understand what is wrong with this query. Can anyone help me to find out why this query is not giving the desired result?
Any suggestions are most welcomed.
The problem is due to the default LIMIT value of every FQL query (LIMIT 100).
Firstly SELECT uid2 FROM friend WHERE uid1=me() query runs and outputs your 100 friends
Secondly SELECT aid FROM album WHERE owner IN (..100 Friends...) query runs and output s100 albums of ur 100 friends.
Finally SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified, like_info
FROM photo WHERE created > 1325356200 and aid IN (...100 Aid...) ORDER BY like_info.like_count DESC LIMIT 30 query runs and outputs the result from 100 albums.
Apparently the result is not at all what u wanted. You might try to increase your limit by yourself (say LIMIT 1000) but it never worked for me. The only way of getting accurate result is trying graph API, but it will take very long time for executing, eventually its a dead choice.
The Proof for my answer
Try to run these codes
SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified, like_info
FROM photo WHERE created > 1325356200 and aid IN (SELECT aid FROM album WHERE owner IN
(SELECT uid2 FROM friend WHERE uid1=me() order by rand() ))ORDER BY like_info DESC LIMIT 30
I used rand() function to randomize the friends
SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified, like_info FROM
photo WHERE created > 1325356200 and aid IN (SELECT aid FROM album WHERE owner IN (SELECT
uid2 FROM friend WHERE uid1=me() ) order by rand() ) ORDER BY like_info DESC LIMIT 30
Here i used rand() to randomize the albums. You can try to randomize the both queries. Every time u execute these codes it will give very different result and you would notice there are many more pictures with many more likes.

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

FQL returns only one photo

I use this query:
SELECT pid FROM photo WHERE owner=$friend_id;
It works fine, but for some users(that has more than 1 photo) this query returns only 1 record.
Then i tried this query:
SELECT pid FROM photo WHERE owner=$friend_id LIMIT 10;
But returned result is the same - only 1 record.
Permissions :
user_activities,
user_photos,
friends_activities,
friends_photos,
publish_stream
What i have to do to get correct result for anyone user??
This depends on the friend's privacy settings for the albums and photos he/she shares/uploads.
Also, I noticed that the owner field in the photo table is not indexable but it is in the album table and hence you may need to use something like:
SELECT pid FROM photo WHERE owner = XXXXXX AND aid IN (
SELECT aid FROM album WHERE owner = XXXXXX
)

Unable to retrieve tagged photo info using FQL

I'm having a hard time running this FQL query.
SELECT pid, src_big FROM photo WHERE pid
IN (SELECT pid FROM photo_tag WHERE subject=me())
The photo_tag table returns a pid that is a much longer string than the usual photo pid.
The inner SELECT statement returns the right number of tagged photos. However, I'd like to get more info on those photos. Any ideas?
which info do you need? if you want more infos, here is the full list of data you can get from the photo table:
http://developers.facebook.com/docs/reference/fql/photo/
about the pid: yes, that is not the "real" photo id. i think you have to select the column "object_id" for the real id.
"The pid is unique only for a given user." - so you cannot really work with it anyway, i guess.
just include those columns from my link you need, like this:
SELECT pid, src_big, object_id FROM photo...