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

Jul 01, 2008 I Scripting.  22,675 views. 
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#2#image]

32 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:

    [quote comment="470"]let’s see if we can integrate it into drupal![/quote]

    I know that’s not going to take you long Tim! Let me know when your done, I can picture it on http://www.millwoodonline.co.uk, very nice.

  3.  Add karma Subtract karma  +1

    Gravatar

    Tim Millwood Says:

    [quote comment="471"][quote comment="470"]let’s see if we can integrate it into drupal![/quote]

    I know that’s not going to take you long Tim! Let me know when your done, I can picture it on http://www.millwoodonline.co.uk, very nice.[/quote]

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

    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:

    [quote comment="493"]Does this only work with php5? love the way it looks, integrating it with the twitter section of my website.[/quote]
    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:

    [quote comment="507"]I got an error:

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

    Please help![/quote]

    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:

    [quote comment="508"]Does anyone have the finished script with links back to the follower’s page?[/quote]

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

  20.  Add karma Subtract karma  +0

    Gravatar

    decomo Says:

    Thanks for the script. Has anyone been able to make this work on a Joomla site? Also, does the script takes any 100 avatars ( assume that’s the limit) from a random starting point or does it always show the latest 100 (or the first 100)? Thanks.

  21.  Add karma Subtract karma  +0

    Gravatar

    Designs Genius Says:

    The script works fine. Unfortunately, to display a twitter avatar mosaic without twitter account link is a real problem for many people and it decrease the popularity of this script.
    I hope this beautiful project will continu to be developed.

    Kind regards – DG

  22.  Add karma Subtract karma  +0

    Gravatar

    Rob Says:

    @Tim – “I think the biggest problem is twitter falling over.”

    Would a good solution be to grab the xml file and store it on the local server instead of reading the xml file from twitter.com? This way you will always a good copy of the xml.

    If the the file returns a null value or an error, it should loop around and try to grab the xml file again.

    You could have the file get updated every 15secs every day.

    I might approach it that way. That way my scripts can read the xml files locally and not be dependednt on twitter.

  23.  Add karma Subtract karma  +0

    Gravatar

    Display your twitter followers on your website or blog | PunitShet.com Says:

    [...] Display Twitter followers 1.1 is an updated version of  Get Twitter Follower Images 1.0 authored by Steve from Sirius Cybernetics Corporation. [...]

  24.  Add karma Subtract karma  +0

    Gravatar

    Punit Shet Says:

    Tried to modify the script to point to the respective followers and was successful in no time. You’ll can check out the updated version at http://www.punitshet.com/display-your-twitter-followers-on-your-website-or-blog/

    Sent an mail to Steve regarding the same and hopefully in no time it will be on his site too.

    For a working demo youll can check out the footer at GoasHOST.com

  25.  Add karma Subtract karma  +0

    Gravatar

    Asko Nõmm Says:

    Very very good, using it with my company website as we speak! :)

  26.  Add karma Subtract karma  +0

    Gravatar

    Paulo Says:

    Please, could you say me how to limit number of avatars to show?

    Tks in advance!

  27.  Add karma Subtract karma  +0

    Gravatar

    John Says:

    This script seems to be broken now. I had it working and it was great, but within the last week or so, it has stopped working returning a ‘String could not be parsed as XML’ error. Did something change with the API?

  28.  Add karma Subtract karma  +0

    Gravatar

    anuradha Says:

    very nice cheers

  29.  Add karma Subtract karma  +0

    Gravatar

    mic Says:

    hi, i try use you code but i cant connect with tweeter maybe change this.

    the code:
    $target = “http://twitter.com/statuses/followers/”.$username.”.xml”;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);
    curl_setopt($ch, CURLOPT_USERPWD, $login);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $gettwit = curl_exec($ch);

    $twitters = new SimpleXMLElement($gettwit);

    $this->twitters = $twitters;
    var_dump( $twitters);

    this the error.. in var_dump()

    object(SimpleXMLElement)#187 (1) {
    ["error"]=>
    string(37) “Basic authentication is not supported”
    }

    maybe the api change, your update the script ?

  30.  Add karma Subtract karma  +0

    Gravatar

    CJ Says:

    13

    This no long seems to work

  31.  Add karma Subtract karma  +0

    Gravatar

    nicoles Says:

    I am looking for it for long time,Thank you very much!!!

  32.  Add karma Subtract karma  +0

    Gravatar

    Yanny Says:

    I don’t know if it’s just me, I get this error:
    Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ in …
    Pointing to this line: $twitters = new SimpleXMLElement($gettwit);

    I haven’t changed the code except for username and password, so anyone has an idea why this error?

Leave a Reply

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

  • connecticut quarry
  • hp support error 1005
  • therapist
  • cspan goldman sachs hearingcspan history
  • buren
  • search engines for jobs
  • axle
  • hp support repair
  • la ink season 6
  • chad ochocinco wedding date
  • vince young 99 yard video
  • dis lyrics
  • vince young football camp
  • connecticut law tribune
  • telex
  • vince young drunk
  • new england patriots store
  • search 990 filings
  • la ink book an appointment
  • flashback
  • hp support hard drive replacement
  • zara phillips queen elizabeth
  • freida pinto jeansfreida pinto kissing
  • tempo
  • chad ochocinco nascar
  • chad ochocinco parents
  • freida pinto can't act
  • bengals xxiii
  • davison
  • battleship aurora
  • greg olsen boulder
  • hp support venezuela
  • la ink 04x01
  • greg olsen twitter
  • hp support number united states
  • zara phillips husband
  • mtv oddities
  • la ink 105
  • freida pinto miral
  • zara phillips baby
  • search engines rankings 2011
  • new england patriots emblem
  • greg olsen football
  • vince young rivals
  • bengals kids jersey
  • slogan
  • la ink season 5 premiere
  • search engines 9
  • randy moss 98 vikings
  • scholarship
  • bengals andy dalton
  • chicago bears expo 2011
  • deja
  • connecticut 5 star resorts
  • bengals for adoption
  • hoffman
  • new england patriots offense
  • percussion
  • bea exhibitors
  • tea party birthday
  • vince young yahoo stats
  • randy moss korey stringer
  • battleship aurora
  • copperhead
  • hp support contact number
  • pumpkin
  • chicago bears jewish players
  • chicago bears bleacher report
  • connecticut secretary of state
  • search engines other than google
  • deleted
  • bengals arrests
  • chicago bears schedule 2011
  • sytem
  • search operatorssearch people
  • youngblood
  • battleship yamato 2010
  • conductor
  • search 78search 800 numbers
  • chad ochocinco yesterday
  • search engines cookiessearch engines definition
  • poodles
  • bengals preseason schedule 2011
  • c span kozol
  • connecticut natural gas
  • bea 71 16
  • cspan facebook
  • la ink members
  • vince young yahoo stats
  • mtv 5 cover
  • search engines of the world
  • chicago bears tattoos
  • randy moss 07 08 highlights
  • kimber
  • bea 2011 map
  • new england patriots rumors
  • vince young jay cutler
  • cartoons
  • bengals qb situation
  • vince young 10 11
  • portugal
  • garcia
  • cervical
  • lynch
  • search lsu.edu
  • beamerbea france
  • randy moss wallpaper
  • chad ochocinco stats
  • connecticut state parks
  • mtv kings of leon
  • simulation
  • brandy
  • bea diy
  • chicago bears 09 draft
  • search 990 finder
  • studded
  • modified
  • bea verdi
  • connecticut 100 club
  • search engines us
  • hp support id
  • battleship layout
  • zara phillips baby
  • chicago bears number 17
  • mtv youtube channel
  • randy moss arrested
  • la ink youtube pixie
  • bea karp
  • presque
  • bea oracle
  • vehical
  • cspan kucinich
  • la ink tattoos
  • stash
  • chicago bears 08 record
  • freida pinto 1995
  • chicago bears posters
  • improved
  • zara phillips yachtzara phillips zimbio
  • parliament
  • ships
  • search cfisd.net
  • hp support error 1005
  • chad ochocinco 15
  • la ink watch online free
  • shovel
  • vince young 6
  • zara phillips shoes royal wedding
  • chad ochocinco to detroit
  • fastest
  • connecticut limo
  • randy moss yahoo stats
  • implants
  • richards
  • search engines no follow
  • new england patriots jake locker
  • bengals tryouts
  • connecticut 97.7connecticut attorney general
  • c span video contest
  • zoning
  • digitizing
  • zara phillips school
  • wamu
  • dis systems
  • new england patriots gillette stadium
  • tea party obama
  • rearend
  • chad ochocinco traded
  • new england patriots needs
  • bengals cheerleaders tryouts 2011
  • lycoming
  • randy moss university
  • freida pinto can't act
  • greg olsen combine
  • connecticut 30 news
  • bear gryllsbea hive dance studio
  • bea 71 series staples
  • new england patriots wiki
  • demarini
  • chad ochocinco ultimate catch cast
  • feature
  • mtv dougie
  • pleated
  • c span yesterdayc span zelaya
  • hayes
  • search chuck norris
  • bengals football
  • search engines before google
  • tea party ribbons