Search code examples
phpfacebookapifriend

Facebook api php get specific friend profile


I want to know the date of birth of a specific friend. I'm using something like this. Is possible get this friend profile field?

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

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
$facebook_login = "1";
  } catch (FacebookApiException $e) {
    $user = null;
  }

} else {

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

}



if ($user) {
    $friends = $facebook->api('/me/friends');
    foreach ($friends["data"] as $value) { ?>

      <img src="https://graph.facebook.com/<?php echo $value["id"]; ?>/picture"/> <?php echo $value["name"]; ?>


    <?php }

I can get the complet name and ID of the friend, but I also want to get the date of birth. And of a specific friend, ex. $friend = $facebook->api('/me/friends/friend_id');

Thanks


Solution

  • You'll need to request the friends_birthday permission in your $perms array to access the field you are looking for.

    Also, if you want to be able to access the user's birthday you'll want the user_birthday permission.

    You can read more about these permissions here:

    https://developers.facebook.com/docs/reference/login/extended-profile-properties/