Arjun K P
Arjun K P

Reputation: 2111

enable user_birthday permission facebook birthday in php

I m making a facebook app to display the birthday of a user.........

     <?
         require_once('php-sdk/facebook.php');
         $config = array(
                          'appId' => 'YOUR_APP_ID',
                          'secret' => 'YOUR_APP_SECRET',
                         );

         $facebook = new Facebook($config);
         $user_id = $facebook->getUser();
     ?>
     <html>
     <head></head>
     <body>

     <?
            if($user_id) 
            {

                  // We have a user ID, so probably a logged in user.
                  // If not, we'll get an exception, which we handle below.
                  try 
                  {

                        $user_profile = $facebook->api('/me','GET');
                        echo "Name: " . $user_profile['name'];

                        // Birth Date to be printed here........
                       echo "DOB:  ".$user_profile['birthday'];
                  } 
                  catch(FacebookApiException $e) 
                  {
                       // If the user is logged out, you can have a 
                       // user ID even though the access token is invalid.
                      // In this case, we'll get an exception, so we'll
                      // just ask the user to login again here.
                     $login_url = $facebook->getLoginUrl(); 
                     echo 'Please <a href="' . $login_url . '">login.</a>';
                     error_log($e->getType());
                     error_log($e->getMessage());
                  }   
             } 
             else 
             {

                    // No user, print a link for the user to login
                    $login_url = $facebook->getLoginUrl();
                    echo 'Please <a href="' . $login_url . '">login.</a>';

              }
     ?>

     </body>
     </html>

Now , the problem is This prints the name as expected but prints nothing in place on date of birth.......When i referred further, I heard about the term facebook permissions (extended)..... and from the following link http://developers.facebook.com/docs/reference/api/user/

I found that we need to enable permissions users_birthday or friends_birthday.

Now, How do we enable it in php code ??...Please help with samples....... I m sorry if this question seems silly. I m just a new comer in facebook app developing and also a beginner in php....... I tried the other examples in stackoverflow.com and it didn't help me much......

Upvotes: 4

Views: 11590

Answers (2)

meetnick
meetnick

Reputation: 1196

You have to ask Facebook to approve your Application. After facebook review it, you are able to use Extended Permissions.

According with this Documentation, if your app asks for more than than public_profile, email and user_friends, it will require review by Facebook before your app can be used by people other than the app's developers. 1

I had the same issue than you. I thought it was wrong coded, everything. Then I just saw this on facebook v2.0 Documentation.

Upvotes: 3

Igy
Igy

Reputation: 43816

I see no indication you've read the Permission or Authentication documentation; you're not asking the user for permission to access their birthday.

Add user_birthday to the scope when sending the user to the Auth Dialog and you'll be able to access their birthday if they approve the permissions.

The permissions you configure in the App Settings only apply to (deprecated) Authenticated Referrals or the App Center login screen, your app needs to explicitly ask for the permissions in all other login flows

Upvotes: 4

Related Questions