How to show the avatars of your twitter followers on your website
Jul 01, 2008 I Scripting. 1,347 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 78 downloads to date...


(3 votes, average: 4.67 out of 5)

Tim Millwood Says:
let’s see if we can integrate it into drupal!
July 1st, 2008 at 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.
July 1st, 2008 at 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.
July 2nd, 2008 at 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.
July 2nd, 2008 at 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.
July 2nd, 2008 at 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!
July 2nd, 2008 at 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.
July 2nd, 2008 at 2:23 pm | Quote deep.thought's commentCannonGod Says:
I have to admit my n00biness here. I’ve searched all over the web for something like this, but sadly my skills as a web programmer are limited :¬(
I’m trying to implement your script into my tumblr blog (http://cannongod.tumblr.com) ideally at the bottom somewhere, but I need a little guidance as I keep screwing up! >_
September 24th, 2008 at 4:05 am | Quote CannonGod's commenttj Says:
Anyone interested in helping me figure out a way to pull in select twitter friends (like 10) into 1 feed, sorted by publish date, with their avatar and status? Im desperate
October 3rd, 2008 at 10:10 pm | Quote tj's commentTim Allard Says:
Does this only work with php5? love the way it looks, integrating it with the twitter section of my website.
October 6th, 2008 at 11:54 am | Quote Tim Allard's commentdeep.thought Says:
Tim Allard said -
It’s looking good Tim, love your Facebook type theme by the way!
October 18th, 2008 at 4:06 pm | Quote deep.thought's commentdeep.thought Says:
Yikes, have you seen the length of the Twitter timeline on abergavenny-online? Might need a little prunning…
October 18th, 2008 at 4:28 pm | Quote deep.thought's comment