How to show the avatars of your twitter followers on your website
Jul 01, 2008 I Scripting. 22,675 views.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]


Tim Millwood Says:
let’s see if we can integrate it into drupal!
July 1st, 2008 at 7:37 pm |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.
July 1st, 2008 at 7:51 pm |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.
July 2nd, 2008 at 8:58 am |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.
July 2nd, 2008 at 9:44 am |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.
July 2nd, 2008 at 9:52 am |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!
July 2nd, 2008 at 1:32 pm |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.
July 2nd, 2008 at 2:23 pm |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! >_
September 24th, 2008 at 4:05 am |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
October 3rd, 2008 at 10:10 pm |Tim 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 |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]
October 18th, 2008 at 4:06 pm |It’s looking good Tim, love your Facebook type theme by the way!
deep.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 |Dale Hurley Says:
You are a champ!
January 15th, 2009 at 12:25 pm |deep.thought Says:
Thanks Dale,
January 15th, 2009 at 8:48 pm |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
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?
January 28th, 2009 at 1:46 am |Marko Says:
I got an error:
Fatal error: Cannot instantiate non-existent class: simplexmlelement in mysite.com/followers.php on line 22
Please help!
February 26th, 2009 at 9:03 pm |Tim Says:
Does anyone have the finished script with links back to the follower’s page?
March 30th, 2009 at 4:21 pm |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.
May 31st, 2009 at 2:13 pm |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.
May 31st, 2009 at 2:18 pm |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.
June 24th, 2009 at 12:52 am |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
July 20th, 2009 at 10:49 am |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.
October 20th, 2009 at 8:25 pm |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. [...]
October 25th, 2009 at 1:23 pm |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
October 25th, 2009 at 1:38 pm |Asko Nõmm Says:
Very very good, using it with my company website as we speak! :)
February 7th, 2010 at 2:59 pm |Paulo Says:
Please, could you say me how to limit number of avatars to show?
Tks in advance!
February 24th, 2010 at 2:01 am |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?
June 9th, 2010 at 8:22 pm |anuradha Says:
very nice cheers
October 1st, 2010 at 12:11 pm |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 ?
October 3rd, 2010 at 8:10 am |CJ Says:
13
This no long seems to work
November 17th, 2010 at 12:01 am |nicoles Says:
I am looking for it for long time,Thank you very much!!!
December 11th, 2010 at 3:51 am |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?
January 3rd, 2011 at 2:21 pm |