user984621
user984621

Reputation: 48453

PHP Facebook API - cannot obtain birthday from API

I have a very simple Facebook app based on this authentication code:

$session = $facebook->getUser();

if (!$session) {
    $url = $facebook->getLoginUrl(array(
               'canvas' => 1,
               'fbconnect' => 0,
               'scope' => 'publish_stream, email, user_activities, user_birthday, user_hometown'
               //'req_perms' => 'publish_stream,email,user_location,user_birthday,user_hometown'
           ));
    echo "<script type='text/javascript'>top.location.href = 'FB_URL';</script>";
} else {
    try {
        $uid = $facebook->getUser();
        $me = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        echo "<script type='text/javascript'>top.location.href = 'FB_URL';</script>";
    exit;
    } 
}

echo "\n === \n";
print_r($uid);
echo "\n === \n";
print_r($me);

The output is:

=== ID_VALUE === Array ( [id] => ID_VALUE [name] => NAME [first_name] => FIRST_NAME [last_name] => LAST_NAME [link] => PROFILE_URL [username] => USERNAME [gender] => male [email] => EMAIL [timezone] => 2 [locale] => en_US [verified] => 1 [updated_time] => 2012-05-16T13:00:04+0000 )

I would expect that after specifying the extended permissions user_birthday and user_hometown I should get in the array also the information about users' birthday and hometown... but unfortunately these information are missing there...

Am I missing something or what am I doing wrong?

Upvotes: 0

Views: 4216

Answers (1)

divide by zero
divide by zero

Reputation: 2370

I did some investigation,

Can you try this: $me = $facebook->api('/me?fields=birthday'); and

for the scope - you request right permission, it's user_birthday

Make sure your $facebook object has access_token

Take a look and report back, i will try to help.

EDIT: I don't understand where from you get FB_URL, since you write LoginUrl in $url variable I reviewed your code and suggest you to try this way:

if (!$session) {
    $url = $facebook->getLoginUrl(array(
              'redirect_uri' => //SET back to your page or whenever you need
               'scope' => 'publish_stream, email, user_activities, user_birthday, user_hometown'          
           ));
    echo '<script type="text/javascript">top.location.href =' . $url . '</script>';
} else {
    try {           
        $me = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        echo $e->getMessage();       
    } 
}

Additionally validate user access token for all rights Get $facebook->getAccessToken(); and debugit here -> Token debugger

Upvotes: 4

Related Questions