Skip to content

Instantly share code, notes, and snippets.

@dukenmarga
Created August 19, 2014 04:49
Show Gist options
  • Select an option

  • Save dukenmarga/d10460ac6fe523907e77 to your computer and use it in GitHub Desktop.

Select an option

Save dukenmarga/d10460ac6fe523907e77 to your computer and use it in GitHub Desktop.
get profile picture from twitter
<?php
/**
* @author Duken Marga
* dukenmarga [at] gmail.com
* Get profile picture from twitter
* You can clean up and optimize the code
**/
getImageTwitter('dukenmarga');
function getImageTwitter($account = 'dukenmarga'){
$url = 'https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=$account&count=1';
$xml = simplexml_load_file($url);
foreach($xml->children() as $status){
foreach($status->children() as $item){
if($item->getName() == 'user'){
foreach($item->children() as $profile){
if($profile->getName() == 'name'){
$name = $profile;
}
if($profile->getName() == 'location'){
$location = $profile;
}
if($profile->getName() == 'description'){
$description = $profile;
}
if($profile->getName() == 'statuses_count'){
$statuses_count = $profile;
}
if($profile->getName() == 'friends_count'){
$friends_count = $profile;
}
if($profile->getName() == 'followers_count'){
$followers_count = $profile;
}
if($profile->getName() == 'profile_image_url'){
$img = $profile;
}
}
}
}
}
echo "<a href='http://twitter.com/$account' title='$name'>
<img class='profpic' src='$img' /></a>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment