
The other day I was working on a small project of mine, and it doesn’t use a content management system such as WordPress or Joomla. It’s just all html and css to style the pages. So I wanted to display my last tweet from twitter, and jazz it up using css. Now when people usually want to display their last tweet, and are running wordpress, they usually just install a plugin to do it for them.
Now remember my site is only HTML and CSS. So I looked into the Twitter API, and found a way you can display your last tweet using the twitterCallback javascript function. I have summed it up in a few easy to follow steps. And its hardly any code at all! (icon by dryicons)
First, decide where about on your page you want your last tweet to display. Then paste in this line of HTML.
[html]<div id=”twitter_update_list”>
</div>[/html]
Next you need to put these 2 lines of JavaScript below the code in step 1. On the 2nd line of code where it says 12345.json, you need to replace 12345 with your twitter username. So mine would be webdesigndev.json.
[js]<script type=”text/javascript” src=”http://twitter.com/javascripts/blogger.js”>
</script>
<script type=”text/javascript” src=”http://twitter.com/statuses/user_timeline/12345.json?callback=twitterCallback2&count=1″>
</script>[/js]
Now you will have a plain text version of your last tweet being displayed. So simple! Continue reading below to find out how to style your little twitter widget using CSS, and even customize it by playing around with some of the Twitter API Parameters.
Of course all webdesigners should perform some sort of styling to their last tweet, to jazz it up a little. At the moment your last tweet is displayed as a bullet list. To remove this and make it pure plain text, put this in your CSS Stylesheet.
[css]#twitter_update_list li {
list-style-type: none;
}[/css]
Then, you can change the colour of the main tweet text. If I wanted to make the text orange and then background black, i would put…
[css]#twitter_update_list span {
color: #FFCC00;
background: #000000;
}[/css]
Then you can style the links within your last tweet, and style when happens when you hover over them. An example would be the following.
[css]#twitter_update_list span a {
display: inline;
color: #000000;
}
#twitter_update_list span a:hover {
text-decoration: underline;
color: #666666;
}[/css]
I have styled mine using CSS, and come out with something that looks like this…

You can play around with the CSS, and what you want your widget to look like.
Twitters API is very big. You can play around with many of the different settings for the twitterCallback function. You can view the api documentation over at this link.
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
Enjoy!
Today, I am giving away Web Design Riches, the ultimate guide on how to run a profitable web design business. Enter your name and email below to get instant access.
MateToth (2 years ago)
This is what i was looking for.
Thanks a lot, it was a really useful post.
An other useful elemnt of the code is “count=x”
Write the number of the tweets you want to display.
Carter Cole (2 years ago)
i made some javascript code so you can embed other peoples tweets when they are cool or important for news stories directly into posts and websites
elvi (2 years ago)
i tried doing what you posted there but it gives me a list of clickables that says something like “about 11 hours ago” and so on.
it doesn’t even show me my latest tweet.
Andy (2 years ago)
Hmm, have you tried styling it via css? It might be hiding the last tweet.
Have you got a link you can post to show me?
Nick (2 years ago)
Hi, I was wondering how you can make it show the date and time… I haven’t really tried it yet but I’m in the process of setting up.
Andy (2 years ago)
Have you styled it with any css at all?
Jeff (2 years ago)
Do have any ideas how to replace in-tweet links with an image such as an arrow and hide the actual link?
Andy (2 years ago)
You could try something like this…
#twitter_update_list span a {
display: inline;
font-size: 0px;
width: 16px;
height: 16px;
background: url(/images/arrow.png) no-repeat;
}
#twitter_update_list span a:hover {
text-decoration: none;
}
This would hopefully display a 16 x 16 pixel image instead of links.
Dude (2 years ago)
Hi! Cool post, but I´m kind of confused… I don´t see the “12345.json” in the second line of the code, what do you mean by replacing that? Cheers!
Andy (2 years ago)
Hey, Its in the 3rd line of code…
src=”http://twitter.com/statuses/user_timeline/12345.json?
And you replase 12345 with your twitter username.
Niki (2 years ago)
i have tried this but for nothing is displaying
Niki (2 years ago)
now it shows the tweets but not the latest it shows all the tweet
Andy (2 years ago)
Put this…
&count=1
At the end of your query. Like…
username.json?callback=twitterCallback2&count=1
Nick (2 years ago)
I like the simplicity of the snippet they provide, but I’ve noticed that probably 85% of the time, nothing actually gets loaded. I’m not sure if it’s hitting an API call limit (only up to 100/hr) but that seems unlikely since I’m just testing it in a dev environment (I don’t get that much traffic anyway hehe).
I’ve since used a jQuery based plugin that does a scrape using search.twitter.com. Maybe not ideal, but at least it works.
Anyone else have the same issues with the Twitter provided snippet?
terry (2 years ago)
I get asked for a username password when i test it. Anybody else have this problem?
aShocka (2 years ago)
read the twitter’s instructions – it says you have to have a public profile. when you unlock it in your settings, it will show.
sriganesh (2 years ago)
ahh. thank you, i will try it. thank you, I WAS LOOKING FOR THIS, TO ADD CUSTOM TWITTER UPDATES.
Jacob (2 years ago)
This works great for me. Only problem I have is it’s displaying all my tweets from my twitter account. How do I only display a set amount? is it the count?
Andy (2 years ago)
Put this…
&count=1
At the end of your query. Like…
username.json?callback=twitterCallback2&count=1
Jacob (2 years ago)
Yep, tried that.
.json?callback=twitterCallback2&count=1
When you take out the ; before the count it no longer displays anything.
Catalin (2 years ago)
Hey thank you for this but a question: how can I minimize the number of tweets because I used count=1 and I get last 20 tweets?
Catalin (2 years ago)
Had to remove the “;” from your initial code line: twitterCallback2&;count=1\
Working fine now
dinsky (2 years ago)
Thanks for providing this, but I can’t get it to display anything at all.
Here’s a link the the page I’m trying to get it to work on. It’s at the bottom of the page in the footer: http://www.viddyworks.ca/v2/index.html
Andy (2 years ago)
Have you put your username in the line of code?
john (2 years ago)
Yo have the code “twitterCallback2&count=1″ on your page.
Should be “twitterCallback2&count=1″
Myfacefriends (2 years ago)
nice tutorial thanks
kees (2 years ago)
Awesome tutorial!,,,,,i have my user name in the script and i have the whole css but it doesn’t work…..i have tried it on a div and on a image but i doesn’t work..? any idea?….something wrong with the API?
Thanks in advance
Kwamepocho (2 years ago)
Worked ok for me…I was having problems until I clicked to view source code icon and recopied the javascript links. Didnt have any issues again…
kees (2 years ago)
It works now!
ote tatsuya (2 years ago)
great tutorial…I’m a newbie on CSS..How can I put a picture like you have done..beside the status’s text..thank you
Sean (2 years ago)
I’ve tried this but it doesn’t seem to be showing any tweets. help?
Keiron Lowe (2 years ago)
Hi, How would I get it to show the users avatar?
And have a space between each tweeet?
Sue (2 years ago)
Fantastic just what I needed worked first time (doing a redesign of my site at the moment so it’s not live yet)
I tried to get the arrow to show it didn’t work so not sure what to try instead of your suggestion above
any other ideas?
css code reads…………
#twitter_update_list li {
list-style-type: none;
}
#twitter_update_list span {
color: #34545c;
font-size: 13px;
font-weight: normal;
}
#twitter_update_list span a {
display: inline;
font-size: 0px;
width: 16px;
height: 16px;
background: url(/images/bn-rr.gif) no-repeat;
}
#twitter_update_list span a:hover {
text-decoration: none;
}
other than that you have explained it very well thank you
koen (2 years ago)
hej,
is there a way.. so the script doesn’t reload the page content??
it messes up the other javascript on my site.
Sean (2 years ago)
Koen, I guess the problem resides in javascript libraries, It’s because which in most cases they are conflicting because most of of the javascript libraries uses $ as an object…
–
Thanks for the sweet share, I’ve been looking for it for AGES!
SwEtS (2 years ago)
hey it really helped me a lot..it works dude..!!!!!!!!!
Torque (2 years ago)
For some reason, when I place the code, the page crashes on IE. I think Internet Explorer has a problem with APIs. Is there a work around so that it doesn’t crash?
Alex (2 years ago)
Though its good being able to get the twitter info being able to specify which parts to get/wrap them in spans ect would be good. Though that might be going into the AIP quite a bit more…
Good article though
Creative Ideas (2 years ago)
Nice. Very useful info
Quixotic Media (2 years ago)
Hey, great tutorial. One thing I am having a problem with is setting the hyperlinks a certain color, It seems something I have put in my code is not allowing this. Any ideas? I am designing this for a client on http://one3rdnerd.com see the bottom left of the footer.
dave (2 years ago)
HI, How do i remove the date stamp from the tweet?
BrockWalker (2 years ago)
I found, that if your username has an underscore in it, you need to change “&count=1″ to “&count=2″ Works for me
Sanjay (2 years ago)
everything works fine but each and everytime it is loading it asks for username and password what to do
Tom (2 years ago)
Doesn’t work for me. Nothing comes in. I have set my username, but still nothing
Tom (2 years ago)
when I look at the json call, I see that I’m getting a rate limit error
joe (2 years ago)
thanks for the post,
its working for me fine, however… the “45 mins ago” doesnt get restyled when i apply css to the links but names in the twitter do?? any reason for this? I have changed the page defaults for links to over come that and match them to my desired styling but would prefer to keep things tidy and all in css for the widget itself. any ideas?
also when i am displaying 3 counts there is no padding between posts for they are really tight on top of each other… i have tried to add padding-bottom to a variety of things but all of what i try doesn’t seem to effect the end display??? any clues?
Also, with rate limits and javascript issues… is this a reliable method? have people that are using this method live on their sites had any problems ?
thanks
Greg6 (2 years ago)
This works great, thanks!
A question: I’ve noticed that when the call doesn’t return anything b/c Twitter’s servers are overloaded (happens often!), then it prevents any remaining HTML of loading.. Is there a way to force it to load the rest of the page even if Twitter servers don’t respond?
That would be really useful.
BornA (2 years ago)
hi
Great article man
We can’t access to twitter in our country
can I access my tweets from other api or url and then import it to my self-hosted wordpress blog?!
Neil (2 years ago)
Can’t get it to work in any version of IE. Works great in Firefox though. Anyone else had the same problem?
Is there a fix? Thanks
Wordpress: come mostrare gli ultimi status di Twitter | Gioxx's Wall (2 years ago)
[...] Basato sull’originale di webdesigndev. [...]
tim (2 years ago)
great tutorial,
i dont have enough space to display the entire tweet, is it possible to only display for example 100 characters with … at the end?
thanks in advance
Tim
Globinch (2 years ago)
Write your own Twitter widget in (Recent Tweets) 3 steps using twitter API.
http://www.globinch.com/2010/04/07/write-your-own-twitter-widget-in-3-steps-recent-tweets-using-twitter-api/
Programmer (1 year ago)
Hi,
I can’t get it to work in IE but it works great in Firefox though??
I notice that it sometimes displays in IE, but most of the time it doesn’t.!
Is these problems related to API and hitting call limit?
Is there a fix? Thanks
Patrick (1 year ago)
Hi, awesome code and great tutorial. Only took about 5 minutes and works really well in Chrome.
Here is mine: http://www.patricktayloredwards.com. Its relatively simple at the moment but I will work on it.
Joe:
padding between individual tweets: (put this in the css)
#twitter_update_list li {
padding-bottom: 10px;
}
I’m also trying to work out how to put a to have the timestamp on a new line and in a smaller text.
Cheers
Ivanet (1 year ago)
Really cool, I have inserted in my blog and it works fantastically. Also you can style the list mode directly from the DIV without editing your CSS
Edin (1 year ago)
Is it possible to remove date stamp? and how?
Cheers
Patrick (1 year ago)
It is technically possible to remove the date / time stamp.
Twitter reads the time stamp as a link so you could put this in your css:
#twitter_update_list li a {
display: none;
}
this simply hides the links from the list withing the div named twitter_update_list
Though this does work, it will also hide any links or ‘@something’ that are in your tweets.
So it is not ideal, but if we knew the exact name twitter gives to the timestamp then it should be possible. I think it is ‘entry-date’ but I have not got anything to work yet.
Cheers
shikkaba (1 year ago)
My server was being stupid and not letting me use PHP to call Twitter. The Twitter official ap wasn’t customizable, really. So this helped a lot. Seriously, thank you.
Sean (1 year ago)
THANK YOU! Finally – I have been looking far and wide for this and this is the first one that works!
mattn (1 year ago)
Awesome example – but how did you get rid of your date stamp eg”1 day ago”?
Jonathan (1 year ago)
I made a jquery plugin to work with Twitter. Check it out at http://github.com/jcutrell/jquery.getTweet.js – free of course, and offers a few extra options.
Adam (1 year ago)
When I paste the code in DreamWeaver throws the following error:
“The documents current encoding can not correctly save all of the characters within the document. You way want to change to UTF-8 or encoding the supports the special characters in this document.”
Can anyone help me out?