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(Facebook\GraphNodes\Birthday)#19 (5) { ["hasDate":"Facebook\GraphNodes\Birthday":private]=> bool(true) ["hasYear":"Facebook\GraphNodes\Birthday":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?
答案 0 :(得分:1)
如果我在使用getGraphUser后正确理解了facebook文档,你应该使用$ user_profile-> getBirthday()。哪个应该根据文件将生日作为日期时间返回。
https://developers.facebook.com/docs/php/GraphNode/5.0.0#user-instance-methods
答案 1 :(得分:0)
您可以尝试这样做,因为您需要使用日期对象进行检索:
使用DateTime对象的格式方法:
$user_profile->getBirthday()->format('m/d/Y');