Search code examples
phpfacebook-graph-apisdkfacebook-php-sdk

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"/>';

              }
            }
?>

Solution

  • 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'] . '"/>';