PDA

View Full Version : Getting latest twitter status



RichardKnox
07-07-2009, 10:15 PM
I wrote a little bit of PHP code for no reason and decided to give it out for free. It's really simple and it all does is grabs your latest tweet using the Twitter Search and then echo's it. This could be used to make something like a status signature or whatever if you just then made the value of $tweet into an image. Anyway, I'm not writing that but if you wish to, enjoy yourself.



<?php

// The function that will do the grabbing of the tweet
function getTweet($url) {

// Get the contents of the ATOM file
$feed = file_get_contents($url);
// Make an XML instance of it
$xml = new SimpleXMLElement($feed);

// Using the XML get the tweet, for this we needed to work out the xml structure
$tweet = $xml->entry->title;

return $tweet;

}

// $username is your twitter username
$username = "cleanString";

// This is the API call URL. &rpp=1 means we will only get the latest status
$url = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1";

// Use our function we made earlier to grab our latest tweet and echo it
echo getTweet($url);

?>

Invent
07-07-2009, 10:22 PM
I really don't get why people don't use the public twitter API instead of parsing pages/search feeds ;s.

RichardKnox
07-07-2009, 10:25 PM
I don't know, I just am used to using this. Sure it would be easier to use the public API but where would the fun in that be when you're writing random code chunks.

.:Tom-:.
08-07-2009, 12:33 PM
This dont work mate?

Well it didnt for me :S

entry->title; return $tweet; } // $username is your twitter username $username = "tomtomdjin"; // This is the API call URL. &rpp=1 means we will only get the latest status $url = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1"; // Use our function we made earlier to grab our latest tweet and echo it echo getTweet($url); ?>

thats what came up in browser

Dentafrice
08-07-2009, 01:51 PM
This dont work mate?

Well it didnt for me :S

entry->title; return $tweet; } // $username is your twitter username $username = "tomtomdjin"; // This is the API call URL. &rpp=1 means we will only get the latest status $url = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1"; // Use our function we made earlier to grab our latest tweet and echo it echo getTweet($url); ?>

thats what came up in browser
Did you save it as .php..?

I'd rather use the public API to do it, but this is a nice way too ;)

.:Tom-:.
08-07-2009, 03:53 PM
Ahh,

Fixxed

Want to hide these adverts? Register an account for free!