Facebook FQL returning inconsistent/conflicting results - facebook-fql

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?

Related

Get list of people who liked a status through FQL

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.

Facebook API, Getting name of friend by his ID

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

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)'
}

Retrieve Curated set of Photos from a Page stream

I'm working on an awareness campaign for a nonprofit. We're asking people to upload photos of them holding a sign to the nonprofit's Facebook page. Since they don't show clearly on the timeline, we want to scrape these photos and display them on a page on the nonprofit's website.
Getting all the photos is easy. I'm using the following FQL to get them:
SELECT post_id, actor_id, message, attachment, place, created_time
FROM stream WHERE source_id = PAGE_ID and source_id <> actor_id
AND attachment.media <> '' AND created_time > 1338834720
LIMIT 50
The problem is, there are other photos that people are uploading to the website that we don't want featured in this gallery. What I'd like to do is further filter this result set so we only get photos the page or a page admin has liked or commented on. This is where I'm getting stuck.
When I convert this to a multi-query and feed the results of the query above into:
SELECT post_id FROM like WHERE user_id = PAGE_ID AND post_id IN (SELECT post_id FROM #query1)
I get an OAuth error that I can only query like for the logged in user. This happens even when authenticating as the app using the PHP SDK.
I've tried getting people to add a text string to their message when they post, but that's not happening. Some people are adding that string to photos the nonprofit doesn't want and the best photos in the nonprofit's eyes don't have that string in them.
Thanks for your help.
Ok, answered my own question.
I'm using this FQL multiquery via the PHP SDK to get the curated group of photos. I settled on a comment made my any page admin:
{
'activity':
"SELECT post_id FROM stream WHERE source_id = PAGE_ID
AND attachment.fb_object_type = 'photo' AND created_time > 1338834720
AND comments.count > 0 LIMIT 100",
'commented':
"SELECT post_id, text, fromid FROM comment
WHERE post_id IN (SELECT post_id FROM #activity)
AND fromid IN (SELECT uid FROM page_admin WHERE page_id = PAGE_ID)",
'accepted':
"SELECT post_id, actor_id, message, attachment, place, created_time, likes
FROM stream WHERE post_id IN (SELECT post_id FROM #commented)
ORDER BY likes.count",
'images':
"SELECT pid, src, src_big, src_small, src_width, src_height FROM photo
WHERE pid IN (SELECT attachment.media.photo.pid FROM #accepted)",
'users':
"SELECT name, uid, current_location, locale FROM user
WHERE uid IN (SELECT actor_id FROM #accepted)",
'pages':
"SELECT name, page_id FROM page
WHERE page_id IN (SELECT actor_id FROM #accepted)",
'places':
"SELECT name, page_id, description, display_subtext, latitude, longitude
FROM place WHERE page_id IN (SELECT place FROM #accepted)"
}
The live site is here: http://getwellgabby.org/show-us-a-sign. Lots of PHP on the back end to combine the results and using ThickBox for the photo display.
Try doing your queries as Batch Requests. You can „name” queries in there to reference their results in other queries, and you can specify different access tokens for each individual operation.