I wrote an FQL query to get names of friends who tagged me -
This is the FQL query which gives me the list of the friends ID's(It's Works):
SELECT owner FROM photo WHERE object_id IN (SELECT object_id FROM photo_tag WHERE subject=me())
Now i want to get their names by querying with this :
SELECT name FROM user WHERE uid IN (SELECT owner FROM photo WHERE object_id IN (SELECT object_id FROM photo_tag WHERE subject=me()))
But i don't get the full list of the names, and it's stops and gives this error - "Uncaught TypeError: Cannot read property 'name' of undefined"
Your query may be failing because some of the owner ids returned by your inner query don't belong to users. Try it with the profile table instead:
SELECT name FROM profile WHERE id IN
(SELECT owner FROM photo WHERE object_id IN
(SELECT object_id FROM photo_tag WHERE subject=me()))
Related
I can get the number of likes on a status through this FQL query -
SELECT like_info,
message,
status_id,
time,
uid
FROM status
WHERE uid = me()
I'd like to get the separate user ID's of the likes (if not possible for friends of the authenticated user, just the user himself/herself). It's possible through the Graph API through a command like this -
me/?fields=statuses
Is the same thing possible through FQL?
You can select IDs from status table for user and then use them to select data from like table
SELECT user_id,
object_id
FROM like
WHERE object_id IN(
SELECT status_id
FROM status
WHERE uid = me() )
You may group result by object_id on your side.
I'm using Facebook's FQL to query:
Fql.execute({
"query1" => "select object_id from photo_tag where subject=me()",
"query2" => "select object_id, subject from photo_tag where object_id in (select object_id from #query1)",
options_dict_with_my_access_token)
query1 gets all photos that have me as a tagged subject
query2 goes to the same table and tries to load those photos with all the subjects
but query 2 fails to load rows for many of the photos that were the result of query1, which is impossible, since i know at least i'm 1 such result.
how does this work?
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
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'
)
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)'
}