views:

2220

answers:

3

Situation:

my facebook application ( http://apps.facebook.com/mymagicmirror/ ) needed to detect user's gender, and then query opposite sex or male or female

FQL:

SELECT uid, name, pic, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user_id.') and sex='male'

Problem: When the facebook user is using other locale, then the 'sex' field doesn't match 'male' and 'female' anymore. Instead, say in Chinese, the sex will become 男性 / 女性, and the FQL for where sex='male' will return zero results.

Any solution to query all male / female friends even if the facebook user is having locale other than english?

+2  A: 

From http://forum.developers.facebook.com/viewtopic.php?pid=174065 :

Just pass english locale (en_US) to the API call and it should return you genders in english (male/female).

You may also find http://forum.developers.facebook.com/viewtopic.php?pid=166744 useful.

Richy C.
sorry, please correct me if I'm wrong, the link you provided only helped fixing 'get user info', but not fixing the FQL.... so matching with "where sex='male'" still fails
Unreality
I believe that if you pass the locale to the API call when making the FQL call, it'll then translate the genders to male/female which will allow your FQL to work. Have you tried it like this?
Richy C.
how to pass the locale to API call during the FQL call? do you mind to give me an example code? many thanks
Unreality
A: 

You need to add &locale=en_US to your GET or POST request being sent by your API client. For example, if you are using the PHP client library provided by Facebook (the latest version released Nov. 2), then you simply need to modify the facebookapi_php5_restlib.php file's post_request function which begins on line 3316.

Replace line 3320:

$url_with_get = $this->server_addr . '?' . $get_string;

With this:

$url_with_get = $this->server_addr . '?' . $get_string . '&local=en_US';
Dustin Fineout
seems not working.
Shivan Raptor
Don't know what to tell you, I haven't been able to replicate this problem at all. When I query, I get the data with no problem.
Dustin Fineout
+2  A: 

Add one of the following functions to your facebookapi_php5_restlib.php file:

Function for users.getInfo:
from: http://forum.developers.facebook.com/viewtopic.php?pid=166745#p166745

public function &users_getInfo_en_US($uids, $fields) {
  return $this->call_method('facebook.users.getInfo',
    array('uids' => $uids, 'fields' => $fields, 'locale' => 'en_US'));
}

Then, you can call users_getInfo_en_US($user, array('sex'));


Functions for FQL:
from the link above but with pid=166866#p166866
One is for the en_US locale (from the post before it) and the other lets you pass in the locale you want to use, like so:

public function &fql_query_localized($query, $locale) 
{
  return $this->call_method('facebook.fql.query',
    array('query' => $query, 'locale' => $locale));
}

Then, just pass in the string 'en_US' for $locale.

Best,

Matt

MattDiPasquale
thank you so much
Unreality