繁体   English   中英

通过Facebook API获取用户的生日

[英]Getting user's birthday through Facebook API

我在使用Facebook API时遇到了一些麻烦,我正在通过Javascript请求对用户的某些信息进行许可:

FB.login(function (response) {
    if (response.authResponse) {
        // authorized
    } else {
        // canceled
    }
}, {scope: 'email,user_birthday,user_location'});

现在,我想通过PHP获取用户的信息(当他被授权时):

$facebookUser = json_decode(file_get_contents('https://graph.facebook.com/' . $this->data['userid'] . '?access_token=' . $this->oathtoken . '&fields=id,name,location,gender,email,picture,birthday,link'));

一切正常,除了API并没有回馈用户的生日。 即使我将生日隐私设置设为公开,也不会显示。

所以:

echo $facebookUser['birthday']; // Gives an error, since this key does not exists

有人知道如何解决此问题吗?

您在客户端登录,但是php在服务器端执行,因此您只收到用户对象的基本信息。

如果您在服务器端登录并具有权限 ,则可以使用以下方法轻松获得生日:

echo $facebookUser['birthday'];

很可能您没有获得从FB请求user_birthday批准。

除非FB检查您的FB应用程序,否则您无法获得user_birthday

可能仅请求以下权限而不进行审查: public_profileuser_friendsemail (请参阅: https : //developers.facebook.com/docs/facebook-login/review/what-is-login-review

age_range ,您只能请求age_range ,而不能请求user_birthday

FB.login(function (response) {
    var user_birthday = response.user_birthday; 
    console.log(user_birthday);
if (response.authResponse) {

} else {
    // canceled
}
}, {scope: 'email,user_birthday,user_location'});

如果您想在服务器端获取FB信息,为什么不使用服务器端身份验证?

如果您可以接受客户端身份验证,则上面的方法应该可行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM