I'm a bit confused.
The docs say:
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.
So I tried, for example:
NSString *fqlStr1 = [NSString stringWithFormat:
#"SELECT actor_id, message FROM stream WHERE source_id = me() AND created_time > %d AND created_time < %d",dayBefore,dayAfter];
This was meant to display all posts between the day before and the day after my birthday...
Which sorta worked..but it only was able to grab like 8 posts... and the posix dates are correct I checked them in a calculator..and its weird when I adjust the times a bit..like making the dayBefore earlier and the dayAfter later...I get a different set of posts but still only like 10....should I do a multiquery in like...1 hour intervals? Whats the reason for this?
-Josh
Try adding LIMIT 5000 to the end of your query.
Related
I am running an FQL query through the Facebook api:
SELECT username FROM page WHERE CONTAINS("Musician/Band")
I am expecting this to return a large amount of items, but it only returned about 100. Is there a limit on the amount of items a query like this will return? Or is this just not a query that is written wrong? In case you couldn't tell, I wanted the usernames of all of the musical artists on FB.
Thank you for your insight.
FQL has LIMIT and OFFSET keywords. You can get upto 5000 results at a time but better way to do it is through pagination
eg:
SELECT username FROM page WHERE CONTAINS("Musician/Band") LIMIT 200 //gets first 200 results
SELECT username FROM page WHERE CONTAINS("Musician/Band") LIMIT 200 OFFSET 201 //to get next 200 results
and so on..
Also you can use Facebook multiquery to minimize number of queries made.
So I'm trying to return the top 4 posts of all the posts, ranked by votes. But I don't want to return any posts that the user already has loaded on his/her page. I have an array of the post pk's the user has loaded to check. But I can't simply exclude posts the query before the slice like this
posts = Post.objects.order_by('-votes')
posts = posts.exclude(pk__in = excludePks)
posts = posts[:4]
Because then if any of the top 4 posts got excluded, I could get the 5th, 6th, 7th, or 8th top posts returned.
I'd like to only exclude posts in the top 4 if one of the pk's matches a pk in excludePks.
I tried filtering after the slice, but as I found out, that's impossible to do because a slice is equivalent to doing a LIMIT in SQL.
posts = Post.objects.order_by('-votes')[:4]
posts = posts.exclude(pk__in = excludePks)
Is there a good way to exclude posts in the top four without getting posts below the top 4 returned as a result?
Not really, but since there's only 4 and you're going to need the data afterwards anyways, filter in Python.
posts = [post for post in Post.objects.order_by('-votes')[:4]
if post.pk not in excludePks]
$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.
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'
I have been using the graph to obtain feed / post information for pages, but have started to use FQL instead as I needed to sort by updated_time rather than the standard created_time sort returned by the graph.
I am using the stream table in FQL and I can get all the information from this I require except the equivalent of the 'type' field (i.e. Status, Link, Photo, Video etc).
When I add type into the fields list for the FQL, I get a int value back (or null) which seems to roughly translate to 46 => page status, 56 => user status, 80 => link ... etc but this field is not documented and this value does not seem to be fully consistent. I've seen a user status be equal to 56 or 237, but not sure what the context difference is to make them change.
The FQL I'm using is:
"SELECT post_id, type, message, description, comments, likes, created_time, updated_time FROM stream WHERE source_id = 40796308305 ORDER BY updated_time DESC" which I'm viewing through the Graph API Explorer /fql?q=
I can get the type information by storing up the ids and making an additional graph call such as "?ids=12345,23456,34567&fields=type" but the goal is to get this in the same call.
Does anybody know how / if this can be achieved?
Many Thanks
This was acknowledged as a bug. See https://developers.facebook.com/bugs/223855374358566