Getting friends status updates and comments using facebook api - facebook

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

Related

Facebook FQL getting all my friends last position update

I'm trying to get all my friend's last position update with this fql query:
SELECT author_uid, message, latitude, longitude, timestamp FROM location_post WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
I would like to take just the latest update for every friend but this query returns me more than one update for a single friend.
I tried to set a limit at the end of the query (equal to the number of my friends) but it does not work.
How I should change it?
If it was a normal database, not a facebook FQL, you could use join and get your results in single query. Unfortunately Facebook FQL does not allow joins or even max function.
But you can:
Receive all the friend ids like in your query
SELECT uid2 FROM friend WHERE uid1 = me()
Then for each friend uid run the query
SELECT author_uid, message, latitude, longitude, timestamp FROM location_post
WHERE author_uid = FRIEND_ID order by timestamp desc limit 1

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.

Friend Status FQL

I am attempting to pull the most recent 50 status updates by friends from Facebook using FQL, but it appears the status table nor the feed table work as expected. I am using the following query, but it's results are only the updates since the last Friday # midnight EST (i.e. at the time of this post 12/07/12 # 12AM EST) which is not enough for my need.
SELECT post_id,actor_id,target_id,message,created_time FROM stream WHERE source_id IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND filter_key = "nf" AND created_time > 1 AND type = 46 ORDER BY created_time DESC LIMIT 50
Is there another way to get the most recent 50 status updates from friends that I can use? I have tried the status table, but there are even less results in it.
From http://developers.facebook.com/docs/reference/fql/stream :
Each query of the stream table is limited to the previous 30 days or 50 posts, whichever is greater, however you can use time-specific fields such as created_time along with FQL operators (such as < or >) to retrieve a much greater range of posts.
Try the status table
SELECT message, status_id, uid FROM status WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY time DESC LIMIT 50
You can try this
SELECT message, status_id, uid FROM status WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me())
ORDER BY time DESC LIMIT 50
but be sure to have the friend permissons messege right ;)

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.

Facebook FQL get list of users and include installed parameter

I would like to get a list of friends of a user. In this list I would like to know which users also have the app installed.
According to https://developers.facebook.com/docs/reference/api/user/ there is an installed parameter that can be accessed through the graph api.
I am trying to do so with the following query but I am having trouble getting the result. (I split the query on multiple lines for readabilty)
var query = "SELECT uid, name, first_name, last_name, pic_square, status, installed FROM user ";
query += "where uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + ")";
query += "order by first_name";
Just had a look at this using the api explorer. You want "is_app_user" as the field for an FQL query and not installed as that doesn't exist in fql but is an api endpoint
fql?q=SELECT uid, name, first_name, last_name, pic_square, status, is_app_user FROM user where uid IN (SELECT uid2 FROM friend WHERE uid1 = me()
or try
https://developers.facebook.com/tools/explorer/433871385166/?method=GET&path=fql%3Fq%3DSELECT%20uid%2C%20name%2C%20first_name%2C%20last_name%2C%20pic_square%2C%20status%2C%20is_app_user%20FROM%20user%20where%20uid%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me())