Filter facebook events by gender with fql query - facebook-fql

There is a certain event that I want to filter by gender with an fql query. This is what I have tried so far
SELECT name, sex FROM friend WHERE sex IN
(SELECT uid2 FROM eid WHERE uid1 = me()) AND sex = "male" LIMIT 10
Any suggestions?
it doesn't do the right thing I want this query to do,
I would like to filter invited members of an event by their gender.

As of v2.0 API querying by gender depends on the users currently using the application. If the user isn't using the application, you will not be able to query the gender.

Related

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.

Ambiguity in friend_Count in user table [FQL] [duplicate]

This question already has answers here:
Fetching list of friends in Graph API or FQL - Appears to be missing some friends
(3 answers)
Closed 9 years ago.
I am working on FQL to retrieve the friends count of a particular user.
When i use the query Select friend_count from user where uid = me() I get a number which is different from the count i get from this query i.e select uid2 from friend where uid1= me()
Why is an ambiguity here?
Does friend_count also includes pending requests then?
If yes how can retrieve those UIDs?
Select friend_count from user where uid = me() returned me X and select uid2 from friend where uid1= me() returned me Y.
My X is greater than Y which makes me think if X includes the pendin g requests but i am not able to find (X-Y).
The difference is that friend_count returns the total number of friends, regardless of their privacy settings.
Counting the results of SELECT uid2 FROM friend WHERE uid1= me() may be lower because users who have either restricted their visibility in Settings->Apps->Apps Others Use or have turned off Platform Apps will never be returned in FQL or Graph API queries.

Order BY 2 fields in FQL

I'm trying to sort friends by 2 criterias those who use my app first and has the most number mutual friends with me. Is there any way to sort by 2 fields in FQL?
I've found work around using mutual_friend_count * is_app_user as a sorting criteria, but it works only for app_user = 1 and doesn't perform sorting for those who is 0.
The original query is:
SELECT uid, name, is_app_user, mutual_friend_count
FROM user
WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND uid != me() ORDER BY (mutual_friend_count * is_app_user) DESC LIMIT 333
Execute in graph API/FQL explorer.
I've found work around using mutual_friend_count * is_app_user as a sorting criteria, but it works only for app_user = 1 and doesn't perform sorting for those who is 0.
Of course it doesn’t, because f.e. 66 * 0 gives the same sorting value as 15 * 0 does.
But assuming no one has a mutual friend count greater than 99999, you could sort by is_app_user * 99999 + mutual_friends_count.
This will give app users a “base value” of 99999, and get the number of mutual friends added. For non-app-users, the base value will still be 0, and get the number of mutual friends added as well.
So app users will have a much higher sort value than non-app-users, and will thereby get ranked first – with the added mutual_friends_count taken into account. Non-app-users will still get ranked by their mutual_friends_count, but only after the app users, because they have a much lower sort value.
The only thing that can be a little tricky, is getting the + sign into the query – it has to be URL-encoded as %2B when passing it to the Graph API Explorer via URL, but it does not show it as part of the query afterwards. But from a look at the result, it seems to be using it in making the query nevertheless:
See example query here.

FQL query returning empty array

I'm just getting started with developing with using facebook api with php.
But I can't seem to figure out why I get only an empty array when I invoke the following query:
$fql = "SELECT message,time FROM status WHERE uid ='".$uid."'";
$response = $facebook->api(array('method' => 'fql.query','query' =>$fql));
print_r($response);
When I use a different query like the following I'm getting result back:
$fql = "SELECT uid2 FROM friend WHERE uid1='".$uid."'";
There may be an issue with permissions. You may need to grant user_status permission.
See here - http://developers.facebook.com/docs/authentication/permissions
Check your permissions. A great way to do this is to use the FQL Query Tool. Its great to test queries and the permissions you will need to access the data you are querying
I have the similar problem, just instead I use:
{
"id":"SELECT uid1, uid2 FROM friend WHERE uid1 = me()",
"posts":"SELECT message, time FROM status WHERE uid IN (SELECT uid2 FROM #id) ORDER BY time DESC LIMIT 50"
}
As a result I get:
{
"name": "posts",
"fql_result_set": [
]
}
If I change uid2 to uid1: (SELECT uid1 FROM #id)
I get my status updates.
2 weeks ago, this was working.
Permissions, in my case are correct.
Note: Query's are in Graph Explorer format, so they can be easyly tested