Created
January 14, 2012 04:03
-
-
Save anonymous/1610208 to your computer and use it in GitHub Desktop.
Grab a twitter user's avatar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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