How to filter FQL queries with fields that are not indexable - facebook-fql

The FQL query below results in a NoIndexFunctionException because 'current_location' is not indexable.
https://graph.facebook.com/fql?q=SELECT%20uid,%20name,%20current_location%20FROM%20user%20WHERE%20uid=me()%20OR%20uid%20AND%20current_location%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1=me())&access_token=CCAAC...
Are there any alternatives for filtering non indexable fields?

There are no alternatives for filtering non indexable fields, Ibrahim Faour, a Facebook employee has explained the technical reasoning behind indexes in this post.

Related

Facebook FQL query returns no results for language field

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

graph api - is it possible exclude id field?

Is it possible exclude id field with "fields" query parameter, for example:
https://graph.facebook.com/zuck?fields=name
I'm not asking for FQL, i'm just curious the possibility to exclude id at this point.

Get posts from user to group with FQL

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.

Query every liked object using FQL

I'm trying to query every object which the user has liked since joining facebook by running this query:
SELECT user_id, object_id, post_id FROM like WHERE user_id=me()
This query runs fine and returns some results, but the number of them is a lot less than I estimated. I tried it on different, real user accounts, and for a friend of mine who has joined facebook around 2006 the number of returned results is still only around 65.
I tried this query through the official javascript sdk and through the graph api explorer which gave identical results.
The documentation doesn't state any limit imposed upon querying the like table.
Is there anything, I should be aware when doing a query on this table?
Thank you very much!
According to this documentation :
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.
Although not explicitly mentioned in the doucmentation for likes, I guess this will be the same limit. So try to add created_time in a where clause.

FQL query: How to select users from the same country

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.