Tamara
Tamara

Reputation: 145

Get facebook permission for birthday PHP SDK

I am trying to get the users birthday from Facebook by the PHP SDK. The weird thing is that we have a similar app with similar code and here it displays just fine. In this app it doens't work unfortunately.

This is facebookCon.php (changed appID and secretID):

<?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('facebookPhpSdk/facebook.php');

$config = array(
    'appId'  => 'MY_ID',
    'secret' => 'MY_SECRET',
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);

$facebook = new Facebook($config);
$uid = $facebook->getUser();

// Login or logout url will be needed depending on current user state.

if (!$uid) {
    $statusUrl = $facebook->getLoginStatusUrl();
    $loginUrl = $facebook->getLoginUrl(array('scope' => 'email','user_about_me','user_birthday','user_location'));
}else{
    $user = $facebook->api('/me');
    $accessToken = $facebook->getAccessToken();
    $logged = true;
}
?>

and this is the page where I would like to display the birthday:

<?php   
$user = $facebook->api('/me');
echo $user['email'];
?>

I can retrieve email, first name, last name, locale etc. but not the birthday.

What did I do wrong?

Upvotes: 1

Views: 4912

Answers (2)

esadude
esadude

Reputation: 47

Facebook have modified their profile permissions for default settings, this morning mine was working but now Birthday, Location and email all have to be Authorised and are not part of the default profile access.public_profile is now just : id, name, first_name, last_name, link, gender, locale, age_range.

Upvotes: 1

Rahil Arora
Rahil Arora

Reputation: 3674

One reason for this can be because you might have disallowed an APP to Access your birthday Or it might be disabled by default. This can be done by the settings under Account Settings -> Apps -> Apps others use. It will give a menu for choosing a particular type of information that apps can access. Something like:

enter image description here

As you can see, it's possible for a user to stop an app from accessing his/her birthday. Make sure that the birthday option is checked. I tried it using Graph API explorer and it was working fine for me.

Upvotes: 0

Related Questions