Kinetic Pulse
  • Home
  • Services
  • Portfolio
  • Blog
  • Terms
  • Contact

Display your last tweet using PHP & Twitter API

October 5, 2009

UPDATE: As of Aug 31st 2010 this method will no longer work. Read an improved way of doing it here: Improved way of getting last Twitter status using SimplePie

Well I figured it would be easy to do – so why has it taken me most of the afternoon to figure it out?!

I was looking for a way to simply get the text of my last Twitter “tweet” and then use the text within my site somewhere.

Ok I shall fess up – the reason I really wanted to know how to do this was for a client who needed to be able to update one line of text on his website, so he can have a lovely ticker tape banner across his site (I kid you not!) – but he didn’t have the budget (or technical know how) to have & use a CMS for his web site – anyway it would be like using a hammer to crack a nut, right?

So I though maybe if I could use the last Tweet he posted in his Twitter account it might be a nice way of getting him to write more on Twitter (great marketing potential yadda yadda…) and a natty way of giving him a mini CMS!

So after a lot of searching – and finding some very complicated solutions doing all manners of things with the Twitter API (which is very mysteriously documented if you ask me) I came up with the following solution – a PHP function that returns the last tweet.

(Note the XML parser I use is only available in PHP5)

status[0]->text;

}

echo twitterCapture();

?>


Kudos goes to this post for starting me off:
http://blarnee.blogspot.com/2009/09/this-is-test.html

There’s probably an easier way of doing this – so I’m interested in any feedback

Here it is in action:
http://www.kineticpulse.co.uk/twitter5.php5

Share

Facebook Google+ Twitter Pinterest Email
  1. pale2hall says

    March 20, 2010 at 4:52 am

    $usersTwitter = "tboltusa";
    $usersTwitterUrl = "http://api.twitter.com/1/statuses/user_timeline.xml?id=" . $usersTwitter ;
    @$xml = simplexml_load_file($usersTwitterUrl);
    echo xml->status->text."\"";

  2. Lollypopstar says

    April 22, 2010 at 10:12 pm

    Thanks for he comment – but for some reason on my set up this doesn't return any thing.
    I don't think it likes the "simplexml_load_file()" function.
    So I'll stick to the above method until I figure out whats happening
    :>

Back to Blog

Testimonials

Amazing and brilliant, Kinetic Pulse have lifted a dream to reality, Highly recommended and great if you are total novice, they know their stuff…Thanks again
Annie LindridgeSalt Yourself Out
Thank you guys so much for all that you’ve done helping us to create a really awesome website!! We get such great feedback – everyone loves it & we couldn’t be prouder! Look forward to working with you again soon!
Wild Thyme PlantsWild Thyme Plants
Thank you for all of your hard work its looks fab and I am over the moon with it!
Amanda MercerAmanda Mercer Ceramics
Absolutely fantastically professional web developer – I would highly recommend!!! Thank you so much Kinetic Pulse!
Tania MarstonDoris Designs
Thanks so much for all your work on this, really appreciated. It’s come on in leaps and bounds since you took over.
Pete KewRedwood Strip Curtains
I like it.  I like it a lot !!!

 You have interpreted what I wanted to achieve perfectly considering what you have to play with i.e not redoing the whole thing in the process.

Fiona Simmons-MooreSouth Gloucestershire Parents & Carers
It’s been fab working with you – we love the site and certainly going to recommend you!
James DaviesThirty Eight Degrees North

Copyright 2026 Kinetic Pulse