skip to Main Content

This might be a simple thing, but I’ m missing out on something. I’m trying to get a birth date out of Facebook Login, when user logs on to my app. I’ve got it all set up, and actually I’m nearly there.

Once successfully logged on, I’m using getGraphUser() function on the response object to extract data, like this:

$user_profile = $response->getGraphUser();

User birthday is returned as a separate object within the array. When var_dumped var_dump($user_profile['birthday']), it looks like this:

object(FacebookGraphNodesBirthday)#19 (5) { ["hasDate":"FacebookGraphNodesBirthday":private]=> bool(true) ["hasYear":"FacebookGraphNodesBirthday":private]=> bool(true) ["date"]=> string(26) "1983-11-18 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(11) "Europe/Riga" }

So, like I said, i’m very close. But not exactly there. Problem is – I cannot get the ‘date’ field out of this. Any suggestions on how to do it?

2

Answers


  1. if i understood facebook documentation correctly after using getGraphUser you should use $user_profile->getBirthday(). Which should according to documentation return birthday as a datetime.

    https://developers.facebook.com/docs/php/GraphNode/5.0.0#user-instance-methods

    Login or Signup to reply.
  2. You can try like this because you need to date object for retrieve:

    Use the DateTime object’s format method:

    $user_profile->getBirthday()->format('m/d/Y');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search