views:

365

answers:

4

Is there a quick way to pull twitter profile image in PHP or Javascript? I need to get the url of the FULL image (not avatar size). Thanks. Any code sample is good.

A: 

I know this isn't the full code sample as requested (because there are several ways of doing this), but do you already have the URL for the avatar? I noticed that turning ".../eric.png" into ".../eric_bigger.png" resulted in the larger image. When "_bigger" already exists, removing it gave me the URL to the original image.

I tested this with several followers' profile images and, when the profile image was > 150px square, worked.

Eric
+3  A: 
function get_big_profile_image($username, $size = '') {
  $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);
}

get_big_profile_image('bobsaget', '_bigger') should return a large avatar: http://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg

get_big_profile_image('bobsaget') should return an even larger image: http://a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg

Adam V.
+5  A: 

No code necessary. There is a service specifically for this reason: tweetimag.es

So for example, my full size profile image would be:

http://img.tweetimag.es/i/sfrench_o

sfrench
A: 

Twitter has a nice simple URL as well.

https://api.twitter.com/1/users/profile_image/abraham

It has size options like "?size=bigger"

You can read more about it here: http://blog.abrah.am/2010/04/little-known-twitter-and-twitterapi.html

abraham