2

我在使用 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

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

4

3 回答 3

2

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

如果您在服务器端登录并拥有权限,那么您可以简单地通过以下方式获取生日:

echo $facebookUser['birthday'];
于 2012-07-18T07:39:28.620 回答
1

很可能您没有收到user_birthday来自 FB 的请求批准。

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

未经审查只能请求以下权限:public_profileuser_friendsemail 参见:https ://developers.facebook.com/docs/facebook-login/review/what-is-login-review )

未经审查,您只能请求age_range,但不能user_birthday

于 2015-07-10T08:54:38.683 回答
0
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 信息,为什么不使用服务器端身份验证?

如果您对客户端身份验证没问题,上面应该可以工作。

于 2012-07-18T08:28:42.527 回答