Jeremy Gwa Jeremy Gwa - 1 year ago 96
PHP Question

facebook get user birthday


I have been struggling to retrieve a users birthday, via PHP.

I look on the net and all the examples given do not work, or have been depreciated.

what is the code to get a users birthday Year day month ?

some clear code would be useful



Answer Source

This uses PHP SDK v4, not v5, however I found it easier to follow, and this persons tutorial is fantastic.

They explain how to retrieve EMAIL in the comments, and if you update it as follows you can get GENDER (Still learning myself so not sure what other fields applies to these steps)

In your index.php, update the following:

<?php if ($_SESSION['FULLNAME'] !="") { 
    <li class="nav-header">Name</li>
    <li><?php echo $_SESSION['FULLNAME']; ?></li>
} ?>

<?php if ($_SESSION['EMAIL'] !="") { 
    <li class="nav-header">Email</li>
    <li><?php echo $_SESSION['EMAIL']; ?></li>

<?php if ($_SESSION['GENDER'] !="") { 
    <li class="nav-header">Gender</li>
    <li><?php echo $_SESSION['GENDER']; ?></li>

The above code looks slightly different from the demo code because I wrapped the

  • lines in an IF BLANK, do not display field.

    In the FBConfig.php file, update the following:

    // see if we have a session

    if ( isset( $session ) ) {
        // graph api request for user data
        // $request = new FacebookRequest( $session, 'GET', '/me' );
        $request = new FacebookRequest( $session, 'GET', '/me?locale=en_US&fields=id, name, email, gender, birthday' );
        $response = $request->execute();
        // get response
        $graphObject = $response->getGraphObject();
        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
        $fbemail = $graphObject->getProperty('email');    // To Get Facebook email ID
        $fbgender = $graphObject->getProperty('gender');    // To Get Facebook gender ID
        $fbbirthday = $graphObject->getProperty('birthday');    // To Get Facebook birthday ID
        /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $fbemail;
        $_SESSION['GENDER'] =  $fbgender;
        $_SESSION['BIRTHDAY'] =  $fbbirthday;

    Birthday isn't working for me like this, but I believe it might be for a few reasons such as additional permissions are needed, I have mine hidden, etc. Hope this helps.

  • Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download