获取Twitter个人资料图片实际链接

时间:2012-07-19 16:38:50

标签: php twitter file-get-contents

我正在尝试获取推特个人资料图片的实际链接。 我知道我可以通过以下链接获取个人资料照片:

 $test = "http://api.twitter.com/1/users/profile_image?screen_name=".$nickname."&size=original"

但是当我想获取此url的文件内容时,它不起作用,因为上面提到的链接被重定向到配置文件图片的实际链接。所以这不起作用:

  file_get_contents($test);     

如何获取个人资料图片的实际链接,然后获取原始尺寸?

2 个答案:

答案 0 :(得分:2)

试试这可能对你有帮助。

<?php
function getTwitterProfileImage($username) {
      $size = '_bigger';
      $api_call = 'http://twitter.com/users/show/'.$username.'.json';
      $results = json_decode(file_get_contents($api_call));
      return str_replace('_normal', $size, $results->profile_image_url);
}
$img =  getTwitterProfileImage('thetutlage');
echo '<img src="'.$img.'"/>';
 ?>

答案 1 :(得分:0)

尝试这是up + direct,

<img class="img-rounded" src="<?php 
    $size = ''; 
    echo str_replace('_normal', $size,$tweet->user->profile_image_url)
?>" 
height="250px" width="400px" />
相关问题