How to I get all the checkins a user is tagged in using FQL - facebook-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

Related

(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

Facebook FQL Location_Post show the author's name

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

Best way to get common "likes" from public info page out of your friends list

I'm trying to get a list of common likes (public) between a user and his friends. I thought this FQL query would work but I'm getting an unknown user error:
--get page_id that you have and any of your friends have
https://api.facebook.com/method/fql.query?query=
select uid, page_id from page_fan where uid in (SELECT uid2 FROM friend WHERE uid1 = me()) and page_id in (select page_id from page_fan where uid= me())
&access_token=ABC
I'm getting this error:
<error_response><error_code>1</error_code><error_msg>An unknown error occurred</error_msg></error_response>
Any suggestions?
It seems that the result set is way to big for the API to handle. Your best bet is to try to limit the result set by either query a set of friends against the user's like or query one, two ...etc pages at a time (if that also didn't work try to LIMIT your friends to say 100 to make sure you are actually getting something). Example of a query:
select uid, page_id
from page_fan
where uid in (
SELECT uid2
FROM friend
WHERE uid1 = me()
) and page_id in (
select page_id
from page_fan
where uid= me()
LIMIT 1
)
Obviously there is no offset in FQL. So first, you need to retrieve the user's likes and then query against them. You can always use the batch api to make multiple calls in a single batch call.
SELECT page_id from page_fan WHERE uid = me() and page_id IN ( SELECT page_id from page_fan WHERE uid = give one hid here )

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.