"sex" field in Users.getInfo in Facebook API - facebook

This is a noob question. According to Facebook API documentation, the sex field in Users.getInfo() function returns values based on users' locale. Hence, determine the gender of user is difficult.
Any solution suggested?

1) This isn't an elegant solution, and perhaps there's a better way that uses the API, but what if you manually created a look-up table for different values of 'sex' in different locales? You could try checking out facebook profiles of people from different countries and get the string displayed for their sex. Then, put that into some kind of dictionary data structure that allows you to grab the M-F string pair based on the locale's code (also given by getInfo()). For example en-US => (male, female), ja-JP => (男性, 女性). Of course, you could try using google translate too. After you gathered this data for a handful of the main locales, you'd be more-or-less covered. Maybe someone on the internets already has done it.
Of course, you could try emailing someone who works on the API for these values. The list of locale codes is here http://wiki.developers.facebook.com/index.php/Facebook_Locales .
2) Here is probably a better solution than (1). If you directly query the FQL User table, the value returned in 'sex' will always be English, starting from February 7 2010. More information about that is here: http://wiki.developers.facebook.com/index.php/User_%28FQL%29 . So, perhaps in the future getInfo() will return only English too. Who knows.
3) The answer to your question is also given on this existing post: Facebook FQL user table `sex` field : how to return male/female even the user is using different locale?

Related

Facebook API - Custom Audience from contact data

does any one has experience with using Custom Audience API in order to create audience for contact data of people outside of U.S.?
Part of the API which i refer to is: https://developers.facebook.com/docs/marketing-api/reference/custom-audience/users/
As you can see, documentation lacks of explanation in what format should be data for COUNTRY field provided. Also I don't know how to format data for ST field if the country is outside of US. Should I use some region name or just leave it blank?
I uploaded 1000 users and nobody has been recognized so I suppose that I just did not format data properly.
Sample request: payload={"schema":["FN","LN","CT","ST","COUNTRY"],"is_raw":true,"data":[["adam","nowak","wroclaw","","poland"]]}&access_token=____&format=json
As you can see I left state field blank, and provided country in English translation and lower caps. It is possible that valid value is e.g. PL a not "poland". Also any information about what should be filled in state field would help me a lot.
Thanks in advance.

What's the best way to create a timezone list to the users using Zend Framework?

I have a trouble with generating a friendly timezone list to the users. For example, you can see a timezone list in google calendar settings. It's an excellent example and I'd like to achieve that.
The list has to be translated in different languages (English, French, Russian, Hebrew).
In the end, I have to create a key=>value list: key - valid timezones, value - user friendly title.
I use Zend Framework and there is the Zend_Locale class that can be used to retrieve the translated cities for timezone. But there is no English translation there (very strange) and the list for timezone-city relation is different for each language.
So, the question is what the best way to get the data?
There's a static method: Zend_Locale::getTranslationList(), which allows you to use some constants:
TimezoneToWindows,
WindowsToTimezone,
TerritoryToTimezone,
TimezoneToTerritory,
CityToTimezone,
TimezoneToCity.
For descriptions, check: http://framework.zend.com/manual/1.12/en/zend.locale.functions.html

Documentation for CONTAINS() in FQL?

There have recently been several questions posted on Facebook.SO using CONTAINS() in the WHERE clause. It seems to work like the Graph API search function, AND functions as an indexed field. All great things for the FQL developer.
SELECT name,
username,
type
FROM profile
WHERE CONTAINS("Facebook")
However, the only official mention of the CONTAINS function appears in the unified_thread documentation. It is mentioned in passing, as a way to search for text contained in a message. It also appeared in this fbrell code sample.
But Contains doesn't seem to be a straightforward search. For example, this query:
SELECT name
FROM user
WHERE CONTAINS("Joe Biden")
returns "Joe Biden" and also "Joseph Biden" and "Biden Joe". But it also returns "Joe Scardino", "Lindsay Noyan" and "Mehmad Moha" among others. What relationship do these people have with the VP of the USA? They aren't my friends, so I'll never know.
There also appears to be the ability to pass CONTAINS a field to search on, however changing the end of my first query to `CONTAINS("Facebook", name) returns an OAuth error:
(#615) 'name' is not a valid search field for the profile table.
In my not-so rigorous testing, I have yet to find a field/table combination that does not return this error.
So what is this mystery function? How does it work? Can it allow us to do things to date impossible in FQL like traversing arrays and filtering data stored in strings?
An answer here would be great, but a description on an FQL functions & methods reference page on the official developer documentation site would be better still.
I don't think that a have any great answers here, but I can give a workaround for the issue of returning unrelated names- which I suspect is because people have made public posts about Joe Biden, liked him, or so on. If you do the following:
SELECT name
FROM user
WHERE CONTAINS("Joe Biden")
AND strpos(lower(name),lower("Joe Biden")) >=0
You will get a resultset that only contains the right names- though it removes the advantage of also returning Joseph Biden, etc. etc.
My personal point of pain is that CONTAINS() appears to work with partial strings (e.g. "Joe Bide") on the profile table, but not on the user table. Very frustrating.

fql bug: page_id is greater that max int value

The developers of facebook states that page_id in the page table is integer.
But because of many facebook pages, it number increased greater that max int value
http://developers.facebook.com/docs/reference/fql/page/
so the fql's select gives smth like this e+123213
This seems like a bug in page table documentation. In Graph API documentation for page object refer to this field as string.
It's actually better to save/use any id returned by Facebook as string since in many cases value of id will cause overflow over integer boundaries. And for some objects id may contain characters other that numbers (underscore).
Update:
To clarify some things. The issue is really not only with documentation but with return data too. API return response as JSON (or if you using old REST API you can specify XML format too) string. So the response do contain full and correct page_id, but in the phase of JSON parsing you loose it due to fact that it's parsed as integer.
In PHP 5.4 json_decode function have additional options parameter which may be JSON_BIGINT_AS_STRING to overcome this issue. You should check if the parsing method you use supports something like this.
There is couple of bugs opened for this issue on Facebook (it's not for the page_id in page table, but same behavior for uid field on other tables):
UID's treated as integers for FQL queries in PHP SDK and exceed PHP_INT_MAX on 32-bit systems
Invalid uid format when fetching FQL page_fan table with fql via GRAPH api
Actually you can do something to overcome this issue:
If you using PHP you may either:
use 64bit version of run-time which have no this issue due to bigger PHP_INT_MAX
use PHP 5.4 with JSON_BIGINT_AS_STRING option passed to json_decode
If you using PHP or any other technology:
use alternative JSON parser (I'm not aware of any JSON parser in PHP that able to handle this)
Use quick and dirty reqular expression to wrap all numbers in response with quotes $response = preg_replace('/(\b\d+\b)/', '"$1"', $response) (this is for PHP, but you'll get the idea)
Also I recommend filing additional Bug on Facebook and updating your question so we can subscribe to it as well.

iphone version of Android contacts attributes?

I'm looking for a way to query contacts in my iPhone app based on a few things. First I only want contacts that have a phonenumber. Second, id like to sort the contacts in order of the number of times contacted.
Android provides attributes that makes this possible and easy to do.
I can't really say that I know the answer, but I believe I know where to find the answer:
http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html#//apple_ref/doc/uid/TP40007744-CH1-SW1
Here are some quotes from that document that seems relevant:
There are two ways to find a person record in the Address Book database: by name, using the function ABAddressBookCopyPeopleWithName, and by record identifier, using the function ABAddressBookGetPersonWithRecordID. To accomplish other kinds of searches, use the function ABAddressBookCopyArrayOfAllPeople and then filter the results using the NSArray method filteredArrayUsingPredicate:.
To sort an array of people, use the function CFArraySortValues with the function ABPersonComparePeopleByName as the comparator and a context of the type ABPersonSortOrdering. The user’s desired sort order, as returned by ABPersonGetSortOrdering, is generally the preferred context.
Those quotes were both found on this page. I hope it helps.