I am trying to build an FQL query that returns post_id's from a specific user to a Facebook group's stream. I can query all posts and iterate through them and pull out what I need, but for a group with a lot of posts, it's not feasible.
The FQL docs lead me to believe I need to use a filter_key in the WHERE clause because actor_id is not indexable. I can't figure out how to use filter_key to get the results I am looking for.
SELECT post_id FROM stream WHERE target_id='a group_id' AND actor_id='a fb_id'
Any help is appreciated!
Here is the query you need:
SELECT post_id FROM stream WHERE source_id=GROUP_ID and actor_id=USER_ID
For this, since you're looking for posts in a group, the GROUP_ID is your source_id. That is an indexable field. Once you have one indexable field in your WHERE clause, you can add additonal fields to it without a problem.
Also, since GROUP_ID and USER_ID are integers, they don't need to be quoted in FQL.
Related
Facebook FQL query returns no results for languages field if there is a clause specifying languages id or name. If there is no WHERE clause for languages then all fields are returned.
SELECT uid,name,languages.name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND (strpos(lower(languages.name), lower("English")) >= 0)
See the following link for an example:
https://developers.facebook.com/tools/explorer?fql=SELECT%20uid%2Cname%2Clanguages.name%20FROM%20user%20WHERE%20uid%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me())%20AND%20(strpos(lower(languages.name)%2C%20lower(%22English%22))%20%3E%3D%200)%20
I have had no problems with other fields or FQL queries. All permissions are requested for authorization token.
Apparently you can't "filter" on fields containing array, filtering on fields containing objects works as you sketched out. I don't think this is documented in the Facbook API docs.
See my answer here as well: FQL Query for facebook
I would like to know if it's possible to get, for example, all the posts that the user liked for the last 6 month.
Tell me if I'm wrong but this query is supposed to return all posts I liked :
SELECT object_id, post_id FROM like WHERE user_id = me()
I don't see how to filter the result.
You cannot grab the post_id that easily from the like table. The ONLY way to get a post_id is querying it from the stream table. This is no arbitrary query.
Here is how you should be thinking about it.
First you have to grab the posts from your stream that were posted by the "owner" since that's the easiest way to arbitrarily grab a bunch of posts that you care about.
select post_id
FROM stream
WHERE filter_key="owner"
Then you have to use that result to check if those post_ids are in your like table AND you're the user that liked them:
select post_id
FROM like WHERE
post_id in (select post_id from stream where filter_key="owner"
and created_time> *timestamp from a week ago*)
AND user_id=me()
I am trying to use FQL to query the stream table and retrieve news feed items. Like this:
SELECT post_id, actor_id, target_id, message, created_time
FROM stream
WHERE filter_key in
(SELECT filter_key
FROM stream_filter
WHERE uid=me()
AND type='newsfeed'
)
AND is_hidden = 0
Following the suggestion here, I've been trying to use epoch timestamps (created_time) to limit the number of items returned and paginate everything (seems like a kludge, but OK, if that's the best we can do). However, any time I specify the cutoff as earlier than a day or so (haven't nailed down the exact pattern yet), it returns null. No error message... just "data": [].
I know there have been a lot of issues with paginating the stream table in the past, but this seems like an old bug (if it's still a bug and not my oversight). Has anyone figured out how to deal with this? I can get better results if I leave any reference to filter_key out of the query, but I need to use it, so that's not really a solution.
I had a very similar issue and I fixed it by removing the
filter_key in
(SELECT filter_key
FROM stream_filter
WHERE uid=me()
AND type='newsfeed'
)
from my query. What I did was initially did a query to get the filter key, and saved the filter_key string to then use in all my subsequent queries. This worked for me
How do I write the FQL query to select users from the same country?
As hometown_location is not indexable, we cannot use hometown_location as the index.
So, how to do that?
You could (if it wasn't an excessive number of users that you were querying) just get all of them with their hometown_location attribute and then filter it yourself.
If you've already noticed that FQL won't let you compare using that column, then you will need to load each of the user's info you are looking at comparing into some array in your code. Then loop thru that array comparing the hometown_location.
I would like to query public posts from multiple Pages.
My FQL query looks like this:
SELECT post_id, source_id FROM stream WHERE source_id in (157528807603192, 127531603328)
This query returns only about 6 records.
However, if I use the two source_id in two separate query I got more than 20 item for both of them:
SELECT post_id, source_id FROM stream WHERE source_id in = 157528807603192
I couldn't find anything in the documentation stating that if you query multiple source_id you need different permissions.
Can anyone explain me what is happening here?
I've found the answer in the documentation. :(
http://developers.facebook.com/docs/reference/rest/stream.get/
"If you specify only one user ID in the source_ids array, you can
return, at minimum, the last 50 posts from that user's profile stream
(Wall) for the last 180 days (it likely can be more).
If you specify more than one user ID in the source_ids array, you can
return posts in those streams only from the last few days (about one
week)."