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

Jul 01, 2008 I Scripting.  494 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 32 downloads to date...

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

7 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  +1

    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.

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