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.
Related
Here is the assumed schema I think is the best to put into place
Users
userId
first_name
age
gender
location (lat,lon)
Matches
userId (voter)
like (vote)
liked_UserId
I know how to find users using the near parameter:
db.users.find({loc: {$near:[-180,40]}}).limit(3)
BUT
1) I'm trying to figure out the best and efficient way of finding users who are the closest and excluding users who have disliked this user. Should I make two query calls??? maybe a $where clause from the other collection somehow?
Edit: I'm thinking make one query to get all the users who have disliked this certain user, then add this array of users as part of a second query in the $nin...but will that be very slow if there are over 400,000 entries?
2) Does Tinder show the user of a profile of another user that disliked them?
I did this query: SELECT id, username, name, pic_square FROM profile WHERE contains('Restaurants in Vilnius, Lithuania'), as a result I got only 23 results. Hovewer if I search for Restaurants in Vilnius, Lithuania search box, in facebook, I get around 200-400 results. Why is that so ?
Facebook limits the API result to 25 items max and you need to use paging to get the next batch: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging
You really shouldn´t use FQL anymore, it will be gone for good after August 2016. Always use the Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
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 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.
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.