ahmad735
ahmad735

Reputation: 45

How to get Profile picture of User Friend's ??

Actually (I am Able to Get User Friend's" Name & ID " But can't get Profile Picture of User Friend's ) This Code take The Friend List and After I Display the User Friend Name , ID , Picture (Picture Don't Display But It not Work )

            <?php
            try {
    $requestFriends = $fb->get('/me/taggable_friends?fields=id,name,picture');

            }           
// Get the Friend List and Store them as a Key Value pair

/// Here The Story Start I am Able to Get  User "Friend Name  & ID " But can't get Profile Picture of User Friend's         /////
            foreach ($friendsArray as $key) {
              {
                     echo $key['name'] . "<br>"; 
                 echo $key['id']."<br>";
echo '<img src="https://graph.facebook.com/' . $key['id'] . '/picture"/>';

              }
            }
?>

Upvotes: 0

Views: 679

Answers (2)

Sourabh Gupta
Sourabh Gupta

Reputation: 1

I want to improve luschn's answer.

Just use

echo '<img src="' . $key['picture']['url'] . '"/>';

instead of

echo '<img src="' . $key['picture']['data']['url'] . '"/>';

Upvotes: 0

andyrandy
andyrandy

Reputation: 74014

You do not get an actual ID, you only get a "tagging token". Check out the returned JSON, the picture URL is already in there:

{
  "id": "xxxxx",
  "name": "xxxxx",
  "picture": {
    "data": {
      "is_silhouette": false,
      "url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/12115682_11736....."
    }
  }
}

For example:

echo '<img src="' . $key['picture']['data']['url'] . '"/>';

Upvotes: 2

Related Questions