Facebook FQL query returns no results for language field - facebook

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

Related

Facebook FQL query on specific fanpage always returns empty result set

I'm trying to determine if a connected user (with the user_likes permission given) has liked one specific fanpage. I'm running the following FQL query:
SELECT page_id FROM page_fan WHERE uid=me() AND page_id = FANPAGE_ID
This always returns me an empty set:
{
"data": [
]
}
However when I run the query without the AND clause:
SELECT page_id FROM page_fan WHERE uid=me()
Facebook returns an array of page_id's that always contains the FANPAGE_ID id from the first query.
Any ideas? Is this a bug? The code used to work.

Querying Facebook Graph using object in the where clase?

Im trying to query the Facebook graph api to retrieve a specific list of photos. I have photo ids stored within an object. Is it possible to insert the object within the where clause of the FQL query and if so what is the syntax?
The query is:
"SELECT object_id, images FROM photo WHERE pid =' " + photos.photoId + "ORDER BY created DESC"
photos is an object containing the user_id and the photoId.
Thanks
Since FQL queries are strings you have to convert all of the PIDs in that object to a string such that you can use the in syntax.
An example of this would be
select uid1 from friend where uid2 in (4,5)

FQL - How do i filter friends based on their work history

I am trying to filter my friends based on work history by using fql, but fql does not return any results.
Here is the fql i am trying:
select uid,username,work from user where uid in (select uid1 from friend where uid2 = $myid) and work.employer.id IN ($someid)
i get the result -
{
"data": [
]
}
Am i doing something wrong?
This is because the work field doesn't obey like the other fields due to how the arrays are set up for each each work object. For example strlen(work.employer.id) gives 0.
So in short FQL doesn't support this feature. You can try submitting a bug report.

Facebook Graph API: get all the friends' likes

I don't particularly fancy the idea of getting a list of friends with 'me/friends' and then iterating over the list to get likes for a particular friend with '%id%/likes' - this takes way to long.
Is there a way to bulk query likes of users' friends in a single API call?
Thanks.
You can use FQL multi-query to get all at once, here is how:
{
"friends":"SELECT name, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())",
"friendsLikes":"SELECT uid, page_id FROM page_fan WHERE uid IN (SELECT uid FROM #friends)",
"pages":"SELECT page_id, name FROM page WHERE page_id IN (SELECT page_id FROM #friendsLikes)"
}
You can test this in http://developers.facebook.com/tools/explorer/
You are going to get three result sets one after another, list of friends, list of all of their likes together and then list of page names.
(Note that the query may take a while to execute, so you may want to put a LIMIT on the first line. After uid1 = me() put a LIMIT 5 for example, for testing...)
Then include it in your code in whatever language/platform you are using, for example on iOS:
http://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/
You can also do the same query using the Graph API:
https://graph.facebook.com/me/friends?fields=name,id,likes.limit(100).fields(id,name)&limit=100
This will solve the issue of the grouping.

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.