Get list of people who liked a status through FQL - facebook

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.

Related

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

Facebook Graph API: How can I search a specific user's statuses for a certain keyword?

I want to be able to search/filter a user's statuses for a certain keyword. I thought I could do something like this:
graph.facebook.com/_user_id_/statuses?q=term
Or even:
graph.facebook.com/_user_id_/search?q=term&type=status
But none of those work and I can't find any documentation on this. I know I can do it with FQL, but the statuses method of the Graph API would give me likes and comments to each status as well.
Any suggestions?
You can do this with FQL, it just takes a multiquery to get it done:
{
'posts_w_keyword': 'SELECT post_id, actor_id, message FROM stream WHERE source_id = me()
AND strpos(message, "keyword") > -1',
'post_comments': 'SELECT post_id, from_id, text FROM comment WHERE post_id IN
(SELECT post_id FROM #posts_w_keyword)',
'post_likes': 'SELECT post_id, user_id FROM like WHERE post_id IN
(SELECT post_id FROM #posts_w_keyword)'
}

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

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.