Facebook FQL Location_Post show the author's name - facebook

I use this query:
SELECT id, author_uid, message, latitude, longitude, timestamp FROM location_post
WHERE author_uid IN
(SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY timestamp DESC";
My question is how can I show the name from the poster because there is no SELECT name FROM location_post. I hope somebody can help me.
Thanks!

Fetch the author_id and make new FQL or graph api request
lets say author_id is 123.
FQL:
SELECT name FROM user WHERE uid = 123
Graph API
http://graph.facebook.com/123?fields=name

You need to do this as a multiquery:
{"locations":"SELECT id, author_uid, message, latitude,...",
"authors":"SELECT name, id FROM profile WHERE id IN
(SELECT author_uid FROM #locations")}

Related

Get events created by friends (but returning their names too)

I can get events created by my friends:
SELECT eid, name, start_time, pic_cover.source, location, venue FROM event
WHERE creator IN (SELECT uid2 FROM friend WHERE uid1=me())
But I want to get my friends names asociated to that events. How can I think of that?
As FQL doesn't support joins between tables, the only solution I can think of is that you match the names of your friends and the events they created in your application.
Therefore, you'd need to issue two separate statements:
SELECT uid, first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())
and
SELECT eid, creator, name, start_time, pic_cover.source, location, venue FROM event WHERE creator IN (SELECT uid2 FROM friend WHERE uid1=me())
and then match them via uid (from the first query) and creator (from the second query).

(Facebook) How to get user check-ins with FQL

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

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

How to I get all the checkins a user is tagged in using FQL

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

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