Reputation: 382696
I have been trying to get a Facebook user's birthday through Facebook Connect but I have not managed to do so. The same code worked previously and still works on other sites made earlier (old ones) but does not seem to work again. Here is the code:
require_once ('./connect/facebook.php');
$facebook = new Facebook("myapi", "mysecret");
$fbuser = $facebook->get_loggedin_user();
if ($fbuser)
{
$_SESSION['custid'] = $fbuser;
$fb_look_fields = array(
'name',
'first_name',
'last_name',
'name',
'timezone',
'name',
'sex',
'birthday',
'birthday_date',
'current_location',
'proxied_email',
'affiliations'
);
try
{
$user_data = $facebook->api_client->users_getInfo($fbuser, $fb_look_fields);
}
catch (Exception $e)
{
echo $e->getMessage();
}
# for birth date
$fb_birthday = $user_data[0]['birthday'];
if (!$fb_birthday)
{
$fql_result_xml = $facebook->api_client->fql_query("SELECT birthday FROM standard_user_info WHERE uid = " . $fbuser);
$fb_birthday = $fql_result_xml['birthday'];
}
echo $fb_birthday;
The birthday is always empty even though I have set it to visible to all.
Has Facebook changed their API/Policy again? Or what am I missing/not doing correctly there in the code?
Upvotes: 3
Views: 8955
Reputation: 11
I had some success to query standard_user_info
table via an offline access_token.
But I cannot find documentation for the date format. The date I get is like "March 4, 1999".
Upvotes: 1
Reputation: 2035
Facebook currently made birthday as extended permission. Did you allow birthday extended permission ? Until user approve birthday extended permission you couldn't retrieve his birthday.
Upvotes: 2
Reputation: 6355
They have changed things up (again). When you build the Login button for Connect, you can request permission to the birthday, like:
The documentation says, "Once the user authorizes your site, you can fetch those fields from the user's profile..."
http://developers.facebook.com/docs/guides/web#login
Upvotes: 2