Friend Status FQL - facebook

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

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

FQL get last 50 photos query returns error

How can i get the last 50 photos uploaded by all my friends ?
I try to run this query in FQL:
SELECT pid, src
FROM photo
WHERE
owner IN (SELECT uid1 FROM friend WHERE uid2=me())
OR pid IN (
SELECT pid FROM photo_tag
WHERE subject in (SELECT uid1 FROM friend WHERE uid2=me())
)
ORDER BY created DESC
LIMIT 50 OFFSET 0
I need to get last 50 photos from all my friends or that my friends where tagged in...
when i run it in the API Explorer i get an error:
{
"error": "Request failed"
}
I know i have sufficen permission becus when i run these 2 query i get results:
SELECT pid, src FROM photo WHERE owner =(me())
and
SELECT uid1 FROM friend WHERE uid2=me()
EDIT:
I have also tried this ..
SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo
WHERE owner IN ( SELECT uid1 FROM friend WHERE uid2=me() )
and created >= 1377800559
ORDER BY created DESC LIMIT 100
how can i get more information ?
is it not possible to run such a query ?
Finnaly !!! Last Posted Photos from all friends...
SELECT pid, src, src_small, src_big, target_id, created, backdated_time
FROM photo where pid in (
SELECT attachment.media.photo.pid
FROM stream
WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid=me()) AND type = 247
)
as you can see my initial approach was all wrong ...
it is actually required to use the stream table to get the latest posts..
then it could be filtered to get only photos posted and use their pid to get all the required info !!! YAY!
I hope it helps other that encounter the same issue..
I'm not sure why, but a weird thing is happening here. When I tried your query- I got
Request failed
Then, after digging a bit I replaced SELECT uid2 FROM friend WHERE uid1 = me() with the IDs and the query worked!
So, as a solution you could first try to get the list of friends with :
SELECT uid2 FROM friend WHERE uid1 = me()
Then use this result in your query as-
SELECT pid, src
FROM photo
WHERE
owner IN (ID1, ID2, ID3 ...)
OR pid IN (
SELECT pid FROM photo_tag
WHERE subject IN (ID1, ID2, ID3 ...)
)
ORDER BY created DESC
LIMIT 50 OFFSET 0
Strange, but this'll work!

Very complex FQL queries very slow

I'm trying to get the first 50 posts (posts by friends) from the user's news feed using facebook FQL, as well as each friend's profile information. I have two queries, which total 10 seconds of processing:
SELECT actor_id, message FROM stream
WHERE filter_key IN
(SELECT filter_key FROM stream_filter WHERE uid= me() AND type='newsfeed')
AND actor_id in (SELECT uid2 FROM friend WHERE uid1 = me())
LIMIT 50
This query returns the user, even if the message is "" (I couldn't find a NOT operator to filter out rows that have "" as a message)
Second query:
SELECT pic_big, name,url from profile WHERE id IN
(SELECT actor_id, message FROM stream WHERE filter_key IN
(SELECT filter_key FROM stream_filter WHERE uid= me()
AND type='newsfeed')
AND actor_id in (SELECT uid2 FROM friend WHERE uid1 = me()))
LIMIT 50
I've tried other ways to get the data (quicker) however, it returns it in a random order (facebook doesn't guarantee that the data comes out the way it went in).
I could place a "loading" animation on my website but I'd prefer not to because I think that this can be optimized but I'm not sure how.
In the past, I used the graph api but I had to process the results myself, and it was very inefficient (taking over 30+ seconds).
For these two queries, you should be able to speed things up quite a bit by combining them into a single multi-query, especially since your second query includes your first query. This one is the most complex, and if you're sending them in separate API calls, Facebook has to perform it twice.
{
'q1':"SELECT actor_id, message FROM stream
WHERE filter_key IN
(SELECT filter_key FROM stream_filter WHERE uid= me() AND type='newsfeed')
AND actor_id IN (SELECT uid2 FROM friend WHERE uid1 = me())
LIMIT 50",
'q2':'SELECT pic_big, name, url, id FROM profile WHERE id IN
(SELECT actor_id FROM #q1)'
}
Your two queries take 4072 + 1304 = 5376ms when I run them in the Graph API explorer. The multiquery takes 3475ms. With network latency eliminated from running two separate queries, this should drastically speed up your app.
You can filter out blank messages by adding AND strlen(message) > 0 to the WHERE part of your first query.
You can use ORDER BY column to force the return of data in a specific order, but there is no guarantee that you will get all the rows in your result.

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

Facebook's fql improper ORDER BY sorting

I have this fql query:
SELECT link_id, owner, owner_comment, created_time, title, summary, url, image_urls
FROM link
WHERE owner IN (SELECT uid2
FROM friend
WHERE uid1 = me())
ORDER BY created_time DESC
LIMIT 0,200;
It's supposed to display last 200 posted links by my friends, but it displays them ordered by owner id ASC then by created_time DESC.
Is ORDER BY in fql limited to one use? How can I make it work?
I suspect the problem is the LIMIT statement. FQL has some odd internal behaviors to optimize their own internal API.
Try removing the LIMIT statement and just give it a specific AND created_time > <point in time> and see if it orders properly. If so, that's why.