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
Related
I can get users check-ins with Graph API but not with FQL.
SELECT place FROM stream WHERE filter_key = 'owner' AND with_location = 'true' AND type = 285
Returns empty result.
SELECT message FROM checkin WHERE author_uid = me()
This returns very old check-ins which is like deprecated table.
How can I get FQL query to work with current users check-ins?
The problem here is that looks like Facebook deprecated checkin table and there are no new checkins here anymore. They started to use location_post table. So to get your checkins you may use
SELECT app_id, coords, author_uid, id, message, page_id, page_type, post_id, tagged_uids, timestamp, type FROM location_post WHERE author_uid = me()
Your attempt is very close. If you want to avoid returning old check-ins, add a where clause for timestamp. For example, if I want to get check-ins for myself during the last 6 months (2678400 seconds in a month), I would do:
SELECT author_uid, tagged_uids, target_id, coords, timestamp, message
FROM checkin WHERE author_uid = me() and timestamp > (now() -
(2678400*6))
If you want to grab checkins of friends, I would do:
SELECT author_uid, tagged_uids, target_id, coords, timestamp, message
FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 =
me()) and timestamp > (now() - (2678400*6))
I want likes count, wall post count and places count of all my friends.
SELECT name ,likes_count, wall_count FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
This returning me list of all of my friends names with their total page likes count and wall post count
but i also need places count of all friends. I think facebook provide it directly like likes and wall post. As in profile we can see total places count just like likes count and friend count and mutual friends count. I have also tried this.
SELECT author_uid, checkin_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) OR tagged_uids IN (SELECT uid2 FROM friend WHERE uid1 = me()) LIMIT 5000
My idea was that i will get it and process it on my application end but it is not returning full list of checkins. How can i get all checkins of my friends with their ids so than i can calculate their total checkins ???
OR if there is a direct way of getting places count then it will be much efficient for my code ...
Don't use any LIMIT.
SELECT author_uid, checkin_id
FROM checkin
WHERE author_uid IN (
SELECT uid2 FROM friend WHERE uid1 = me())
OR tagged_uids IN (
SELECT uid2 FROM friend WHERE uid1 = me())
This works and gives me 737 checkins for all my friends. FQL doesn't have a COUNT function like in SQL, so you will have to enumerate checkins in the language of your choice.
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 ;)
Using the graph api it's possible to do:
https://graph.facebook.com/me/checkins
But how am I supposed to do it with FQL?
I tried this which suggests:
SELECT message FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
AND me() IN tagged_uids
but it doesn't return even a single result.
Thanks.
From what I can see, IN doesn't seem to work with me(). You have to first get the user id and assign this to a variable. This throws an OAuth exception:
SELECT message FROM checkin WHERE author_uid = me() OR me() IN tagged_ids
but if you set [UserId] to the current user's id, this works:
SELECT message FROM checkin WHERE author_uid = [UserId] OR [UserId] IN tagged_ids
You don't need to use the friend subquery. FQL will only return checkins that are visible to your user.
For this to work, make sure your access_token has both the user_checkins and friends_checkins permissions.
#cpilko gave a solution, but I've found another one, so I am adding it here as a reference for whoever reach this page:
SELECT id FROM location_post WHERE ([UserId] IN tagged_uids OR author_uid=me()) AND strpos(type,"checkin")>=0
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)'
}