In my app, a user is at a location and is looking for her friends who have been anywhere withing 10 miles of where she is. How do I find this with either FQL or graph? The only way that I can see is by running a search like so: https://graph.facebook.com/search?type=checkin and then running through the results to find out which location was within 10 miles. Is there a better way for this?
Thanks for your help!
Doles
From http://developers.facebook.com/docs/reference/fql/location_post/
It says
An FQL table that returns Posts that have locations associated with
them and that satisfy at least one of the following conditions:
you were tagged in the Post
a friend was tagged in the Post
you authored the Post
a friend authored the Post
Note: This query can process a large amount of data. In order to
ensure that a manageable amount of data is returned within a
reasonable timeframe, you should specify a recent timestamp to narrow
the results.
Return posts within 10,000 meters of a given location:
SELECT id, page_id
FROM location_post
WHERE distance(latitude, longitude, '37.86564', '-122.25061') < 10000
Although the initial answer did work for me for part of my purpose, it quickly became inadequate. Now, after banging my head against the wall, it finally broke (not my head - the wall). Here are two more BETTER ways that WORK to find what I need:
This is to find just checkins:
SELECT checkin_id, coords, tagged_uids, page_id FROM checkin WHERE
(author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) or
author_uid=me()) and coords.latitude<'45.0' and coords.latitude>'29'
and coords.longitude>'-175' and coords.longitude<'-5';
This is to find all location posts:
SELECT id, page_id FROM location_post WHERE (author_uid IN (SELECT
uid2 FROM friend WHERE uid1 = me()) or author_uid=me()) and
coords.latitude<'45.0' and coords.latitude>'29' and
coords.longitude>'-175' and coords.longitude<'-5'
Related
I currently use the following FQL to search users with name containing "Peter":
SELECT uid, name FROM user WHERE uid IN (SELECT id FROM profile WHERE CONTAINS('Peter'))
How can I know which user is my friend (<-- sounds silly)?
As far as I know, the following FQL can check whether the search result user is friend of me, or not:
SELECT uid2 FROM friend WHERE uid1 = me()
Apart from executing the 2nd query for each of the search result, is there a way to combine both query?
Update: Since FQL is going to be deprecated, Graph API solution is also welcomed.
I am trying to get all links shared by a user's friends I tried all of the queries and requests from the below questions,
How do I get a friend's links with Facebook's graph api?
Finding who shared a link publicly and finding who reshared a given link
Facebook API: All links shared by all friends?
get shared links on facebook newsfeed
but unable to figure out what would be the exact FQL or the request URL to get all links shared from my friends from a defined past interval. I am kind of a newbie with the graph API and FQL, so kindly help me in figuring out a way to do this.
I tried a simple 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() LIMIT 100)
but I get
{
"error": "Request failed"
}
as the response from the API Explorer.
Your query is too long for FQL to construct the answer. If you'll try this:
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() LIMIT 10)
(the same query, only limit set to 10 instead of 100) FQL explorer will think ~5-8secs but then give you back the result. Or if you will not receive the result, you have to reduce limit again.
So you have 2 choices:
You can lower you limit from 100 to 10 or less and run your query without changes
You can run query
SELECT uid2 FROM friend WHERE uid1 = me()
and then for each received friend ID run another query
SELECT link_id, owner, owner_comment, created_time, title, summary, url, image_urls
FROM link WHERE owner = FRIEND_ID
Here is an example query:
SELECT uid FROM page_fan WHERE page_id IN (104266592953439, 16155433, 5768707450)
AND uid IN (SELECT uid2 FROM friend WHERE uid1=me())
This will give me the uids of friends who like either of the above three pages.
I would like a solution that lets me know how many of the pages within the above subset is liked by each friend (provided they like at least one of them). Something that can scale out to 20+ pages within the subset would be ideal.
For example, if a friend likes all 3 of the pages, listing their uid 3 times would suffice. Although I'm not sure if that is possible in FQL.
Using PHP Facebook SDK.
The Graph API doesn't have a count method, so you're going to have to do this in your script.
Change your query above to this:
SELECT uid, page_id FROM page_fan WHERE page_id IN (104266592953439, 16155433, 5768707450)
AND uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY uid
Then loop through your result and count how many times each uid appears.
I am trying to retrieve all my friends' likes using FQL. But I am not getting all the likes only those pages which have "is_community_page" value true are being returned. Here's my FQL query
SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
There is a max limit of 5000 results per FQL query that Facebook imposes before the results are trimmed for Privacy preferences of users. You can read this blog post about the same.
Facebook FQL retrieve a link to have full likes list and a samples list (quite unuseful), the point is not the limit of result, the point is fql has a different approach to list this data.
I stepped into it as well, trying to find a solution atm
$fql = "SELECT link_id, owner, created_time, title, summary, url, image_urls FROM link WHERE owner IN (select uid2 from friend where uid1 = me() LIMIT 20) AND created_time >= $_7ago";
The above query works great. However, when I increase the LIMIT from 20 to, say 21 or anything higher, I get an error and the query returns Null. I am looking to query Links shared by ALL friends. Thanks.
That query takes forever to execute. Just testing it a few times in the Graph API explorer, even getting the links from 20 friends takes > 28 seconds. As I'm writing this, I've got a query running for 100 friends. We'll see if it completes before I do.
It looks like if you want to get all the links shared by all friends, you'll need to break this query up into smaller chunks and repeat it multiple times.
I might structure it like this to get your closest friend's links first, and then dig deeper for people who have less in common with you:
SELECT link_id, owner, created_time, title, summary, url, image_urls FROM link
WHERE owner IN (SELECT uid FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me())
ORDER BY mutual_friend_count LIMIT $offset, 20)
AND created_time >= $_7ago
You'd increment $offset in multiples of 20.
This is best done as an asynchronous query where you'll get the initial results quickly and others will fill in as they become available. It's going to take a LONG time to get all these results.
(100 Friends query still hasn't returned results after 5 mins.)
BTW, don't forget to mark your questions as resolved.