Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2012 04:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1610208 to your computer and use it in GitHub Desktop.
Save anonymous/1610208 to your computer and use it in GitHub Desktop.
Grab a twitter user's avatar
// Grab a twitter user's avatar with php
//
// usage:
// $photo = get_tiwtter_avatar('alexpgates');
//
// requires xmlize to parse xml into an array
// xmlize is available here: https://github.com/rmccue/XMLize
function get_twitter_avatar($u){
$Url = "http://twitter.com/users/$u.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$data = curl_exec($ch);
curl_close($ch);
$arr = xmlize($data);
$photo = array();
$photo['thumb'] = $arr['user']['#']['profile_image_url'][0]['#'];
$photo['big'] = str_replace('_normal.', '.', $photo['thumb']);
if($photo['thumb'] == ''){
return('twitter_error');
}
return($photo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment