How to show the avatars of your twitter followers on your website
Jul 01, 2008 I Scripting. 494 Views. Share ThisA simple PHP script to display twitter followers
I have seen quite a lot of people asking how to get the avatars of their Twitter followers displaying on their website. Well, as a break to custom coding an e-commerce site for a client, I have cooked up a little code that does just that.
In addition to the obvious, that it displays the avatars of your followers on your website, it has a few little extras.
- It displays the total number of Twitter followers above the list of avatars.
- If Twitter falls of it’s perch or decides to return an error, it doesn’t display anything, so no breakages there.
- You need only enter your Twitter username and password in order for it to do it’s thing.
The Twitters Followers avatar list is easy to style using the image class ‘twitter_followers’.
img.twitter_followers {
padding:2px;
display:inline;
height:30px;
width:30px;
}
Would give you something like this, look at the bottom of the page. The page is a work in progress, but you get the idea. If you don’t see anything, Twitter has fallen of it’s perch or decided to pull a ‘too many tweets’ error.
If you find this ‘Twitter_followers’ script useful or have any observations, leave a comment.
Version 1.0
around 32 downloads to date...


(3 votes, average: 4.67 out of 5)

Tim Millwood Says:
let’s see if we can integrate it into drupal!
Jul 01, 2008, 7:37 pm | Quote Tim Millwood's commentdeep.thought Says:
Tim Millwood said -
I know that’s not going to take you long Tim! Let me know when your done, I can picture it on www.millwoodonline.co.uk, very nice.
Jul 01, 2008, 7:51 pm | Quote deep.thought's commentTim Millwood Says:
deep.thought said -
I know that’s not going to take you long Tim! Let me know when your done, I can picture it on www.millwoodonline.co.uk, very nice.
Well it works! I have just put it in a Drupal block on my site for now, but hope to make it into a module over the weekend with a settings page to add twitter login.
Might also convert to show people you are following as well as people following you.
Jul 01, 2008, 8:58 am | Quote Tim Millwood's commentdeep.thought Says:
Looks good, I think that you might be on to something there Tim. Also might be an idea to look at caching the results, so that it only calls once in a while.
Let’s see what kind of interest it gets, if there are lots of comments from people looking for additional features it might be fun to develop it.
Jul 01, 2008, 9:44 am | Quote deep.thought's commentTim Millwood Says:
I think the biggest problem is twitter falling over.
I was going to make each avatar a link to the users twitter page, but the block was not displaying, guess twitter API is dead for the day.
Jul 01, 2008, 9:52 am | Quote Tim Millwood's commentTim Millwood Says:
“http://twitter.com/statuses/followers/”.$username.”.xml”
to
“http://twitter.com/statuses/friends/”.$username.”.xml”
to get a list of your friends rather than your followers.
and change the echo line to
echo "screen_name, “\”>profile_image_url, “\” title=\”", $twit->name, ” from “, $twit->location, “\” alt=\”", $twit->name, ” from “, $twit->location, “\” />\n”;to make the avatar a link and feature the friends location, because not all people have a local I could do with making this an if.I will have to blog about all this later, i’m having great fun!
Jul 01, 2008, 1:32 pm | Quote Tim Millwood's commentdeep.thought Says:
I go to get a sandwich and miss all the fun lol.
For the link you could use something like -
a href=''www.twitter.com\'', $twit->screen_name ,'' />.....Which would link back to their profile. You could try a !empty($twit->url) but I am not sure if that would work, also !isset($twit->url) would be worth exploring.
As for the caching aspect, we would have to empty a MySQL table each time we did a call and write each entry back to the database. Just concerns me that I am uncertain how to check prior to that, that we actually have new data e.g. twitter hasn’t fallen over again (no sense emptying a table if we have no data to stream to create a new one).
I think you might get quite a good uptake of your drupal module if you could cover all the bases against twitter falling of it’s perch.
Jul 01, 2008, 2:23 pm | Quote deep.thought's comment