Facebook权限”;生日;给了我错误的年龄


Facebook permission "birthday" giving me the wrong age

我正在尝试提取使用Facebook登录我的页面的用户的生日来获取年龄。我一直试图用我的个人资料登录,但它给了我错误的年龄。以下是我在process_facebook.php中的代码(我有一个数据库,其中有一个名为"age"的字段,需要一个int):

function getAge($birthday) {
        $dt = strtotime($birthday);
        // convert the birthday to a standard format (UNIX epoch)
        $a = gmdate('Y') - gmdate('Y',$dt);
        // find the difference of years
        $a = (int)$a;
        return $a; // return the age.
    }

在典型的process_facebook.php框架中,我有以下内容:

$birthday = $me['birthday'];

$age = getAge($birthday);

我知道我的生日是1987年1月4日,在Facebook上(应该用$birthday中的字符串"01/04/1987"来表示)。但是,当我的数据库中的字段被填充时,它的数字是43。

我试着把代码"01/04/1987"作为$birthday单独运行,结果它吐出26罚款。

我不知道发生了什么(脸书会不会给我一个不正确的生日?)谢谢你的提前帮助。

如果您确实授予了应用程序user_birthday权限,请检查Graph API资源管理器。在右上角的下拉列表中选择您的应用程序,并用此填充文本框

me?fields=birthday

如果输出中没有birthday字段,您可以单击获取访问令牌查看您授予应用程序的权限。

我认为您的应用程序未授予user_birthday授权,$me['birthday']为空。这就是为什么计算出的年龄是43岁——自1970年以来已经过去了,正如马克·B在评论中指出的那样。要进行检查,只需使用var_dump($me['birthday'])

请务必查看此评论。