How to show the avatars of your twitter followers on your website

Jul 01, 2008 I Scripting.  13,970 Views.  Share This
tagged as 

A 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.

Download Twitter Followers Script Version 1.0

Version 1.0
around 979 downloads to date...

PoorNothing SpecialWorth ReadingPretty CoolAwesome! (8 votes, average: 4.63 out of 5)
Loading ... Loading ...

19 responses so far, say something?

Notes on commenting

By commenting here you are creating a backlink to your site, please consider your landing page before entering details in the 'website' field.
You can read more detailed notes regarding this here.

RSS Feed for latest comments to all posts

  1.  Add karma Subtract karma  +2

    Gravatar

    Tim Millwood Says:

    let’s see if we can integrate it into drupal!

  2.  Add karma Subtract karma  +2

    Gravatar

    deep.thought Says:

    Tim Millwood said -

    let’s see if we can integrate it into drupal!

    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.

  3.  Add karma Subtract karma  +1

    Gravatar

    Tim Millwood Says:

    deep.thought said -

    Tim Millwood said -

    let’s see if we can integrate it into drupal!

    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.

  4.  Add karma Subtract karma  +0

    Gravatar

    deep.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.

  5.  Add karma Subtract karma  +0

    Gravatar

    Tim 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.

  6.  Add karma Subtract karma  +0

    Gravatar

    Tim 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!

  7.  Add karma Subtract karma  +0

    Gravatar

    deep.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.

  8.  Add karma Subtract karma  +0

    Gravatar

    CannonGod 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! >_

  9.  Add karma Subtract karma  +0

    Gravatar

    tj 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

  10.  Add karma Subtract karma  +2

    Gravatar

    Tim Allard Says:

    Does this only work with php5? love the way it looks, integrating it with the twitter section of my website.

  11.  Add karma Subtract karma  +0

    Gravatar

    deep.thought Says:

    Tim Allard said -

    Does this only work with php5? love the way it looks, integrating it with the twitter section of my website.

    It’s looking good Tim, love your Facebook type theme by the way!

  12.  Add karma Subtract karma  +0

    Gravatar

    deep.thought Says:

    Yikes, have you seen the length of the Twitter timeline on abergavenny-online? Might need a little prunning…

  13.  Add karma Subtract karma  +1

    Gravatar

    Dale Hurley Says:

    You are a champ!

  14.  Add karma Subtract karma  +0

    Gravatar

    deep.thought Says:

    Thanks Dale,
    Check this one out. Needs a little organising, but I like this one; changes CSS at sunup and sundown.
    http://www.abergavenny-online.org.uk/timeline/tweets.php

  15.  Add karma Subtract karma  +0

    Gravatar

    Marc Says:

    Awesome script! Having a ton of fun with this at the moment, for some reason when I implement it only shows 100 followers max - cant really figure out how to show more - thoughts?

  16.  Add karma Subtract karma  +2

    Gravatar

    Marko Says:

    I got an error:

    Fatal error: Cannot instantiate non-existent class: simplexmlelement in mysite.com/followers.php on line 22

    Please help!

  17.  Add karma Subtract karma  +1

    Gravatar

    Tim Says:

    Does anyone have the finished script with links back to the follower’s page?

  18.  Add karma Subtract karma  +0

    Gravatar

    deep.thought Says:

    Marko said -

    I got an error:

    Fatal error: Cannot instantiate non-existent class: simplexmlelement in mysite.com/followers.php on line 22

    Please help!

    You need to have php5 working on your web server in order to call the simplexmlelement class. It is ‘non-existant’ in php4.

    Hope that helps.

  19.  Add karma Subtract karma  +1

    Gravatar

    deep.thought Says:

    Tim said -

    Does anyone have the finished script with links back to the follower’s page?

    See Tim Millwoods final comment above, that will do the trick.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Close
E-mail It