2

I'm trying to get the twitter profile picture actual link. I know I can get the profile picture through the following link:

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

but when I want to get the file contents of this url, it doesn't work, cause above mentioned link is redirected to the actual link of the profile picture. So this doesn't work:

  file_get_contents($test);     

How can I get the actual link of the profile picture and then with the size original?

Stefan
  • 155
  • 7
  • 18
  • possible duplicate of [How to get the real URL after file_get_contents if redirection happens?](http://stackoverflow.com/questions/4323985/how-to-get-the-real-url-after-file-get-contents-if-redirection-happens) – poke Jul 19 '12 at 16:43
  • 1
    Not a duplicate, but this can be answered using information from that question – nwalke Jul 19 '12 at 16:48

2 Answers2

2

Try this it might help you.

<?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.'"/>';
 ?>
Aman Virk
  • 3,909
  • 8
  • 40
  • 51
  • I don't know what I am doing wrong but I can't get it to work. Any help would be appreciated. Thanks – lomse Dec 20 '12 at 20:06
  • 2
    {"errors":[{"message":"Sorry, that page does not exist","code":34}]} – Can Aksoy Jan 20 '13 at 21:29
  • 1
    @AmanVirk http://twitter.com/users/show/screen_name.json works no more. Any other workaround available? – lomse May 14 '13 at 15:07
  • For those who still search: As the right question :) - [How to get user image with Twitter API 1.1?](http://stackoverflow.com/q/14836956/367456) – hakre Dec 19 '14 at 16:24
0

Try this is up+direct,

<img class="img-rounded" src="<?php 
    $size = ''; 
    echo str_replace('_normal', $size,$tweet->user->profile_image_url)
?>" 
height="250px" width="400px" />
slavoo
  • 5,798
  • 64
  • 37
  • 39
Josue
  • 1
  • 1