最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Getting user's birthday through Facebook API - Stack Overflow

programmeradmin3浏览0评论

I'm having some troubles with the Facebook API, I am requesting permission for some information of the user by Javascript:

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

Now I want to get the user's information (when he is authorized) by PHP:

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

All working great, except that the API is not giving the user's birthday back. Even when I set my birthday privacy settings on public it won't show up.

So:

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

Does somebody have an idea how to fix this?

I'm having some troubles with the Facebook API, I am requesting permission for some information of the user by Javascript:

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

Now I want to get the user's information (when he is authorized) by PHP:

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

All working great, except that the API is not giving the user's birthday back. Even when I set my birthday privacy settings on public it won't show up.

So:

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

Does somebody have an idea how to fix this?

Share Improve this question edited Jul 18, 2012 at 9:01 Lumocra asked Jul 18, 2012 at 7:31 LumocraLumocra 5452 gold badges6 silver badges16 bronze badges 1
  • I have a similar problem. Interesting, the first time I tried, I did get the birthday, but not on subsequent tries for the same user. I looked at Privacy settings and see that app. has privilege to see my birthday, so that is not the problem. – Milan Babuškov Commented Nov 13, 2012 at 18:33
Add a ment  | 

3 Answers 3

Reset to default 2

You are logged in on the client side but php is executed on the server side so you receive only the basic information of an user object.

If you logged in on the server side and have the permissions so you can get the birthday simply with:

echo $facebookUser['birthday'];

Most probably you didn't receive approval to request user_birthday from FB.

You can't get user_birthday unless FB reviews your FB app.

Only the following permissions may be requested without review: public_profile, user_friends and email (See: https://developers.facebook./docs/facebook-login/review/what-is-login-review)

Without review you can request only age_range, but not 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'});

why don't you use serverside auth if you would like get FB info in server side?

if you are ok with clientside authentication, above should work.

发布评论

评论列表(0)

  1. 暂无评论