0

I want to get the birthday date of a specific friend using facebook api php. I have the friend's id passed from a form with a friend list in te variable $_POST[friend_id]. I'm doing something like this but I can't get the friend data:

$user = $facebook->getUser();
$perms = array('scope' => 'email,user_photos,read_mailbox,friends_birthday,user_birthday,user_likes');

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
    //get friend data
    $friend_profile = $facebook->api('/me/friends/' . $_POST[friend_id]);
  } catch (FacebookApiException $e) {
    $user = null;
  }

} else {    
    die('<script>top.location.href="'.$facebook->getLoginUrl($perms).'";</script>');
}


echo $friend_profile['birthday'];

But I can't see the birthday date.

Thanks

victor
  • 87
  • 2
  • 11

1 Answers1

0

Your API call is wrong, for getting the birthday of a friend you would need this one:

$friend_profile = $facebook->api('/' . $_POST[friend_id] . '?fields=birthday');

And you should remove the first call to the api (/me), because every call needs some time and you don“t use the data.

andyrandy
  • 72,880
  • 8
  • 113
  • 130