如何获得用户朋友的个人资料图片?

时间:2016-09-01 11:32:54

标签: php facebook-graph-api sdk facebook-php-sdk

实际上(我能够获得用户朋友的“名称和ID”但无法获得用户朋友的个人资料图片)此代码采取朋友列表并在我显示用户朋友姓名,ID,图片后(图片Don)显示但不起作用

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

              }
            }
?>

2 个答案:

答案 0 :(得分:2)

您没有获得实际ID,您只能获得一个标记令牌&#34;。看看返回的JSON,图片网址已经在那里:

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

例如:

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

答案 1 :(得分:0)

我想提高luschn的答案。

只需使用

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

而不是

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