Just like the Google Charts API the Twitter API can be super simple. Twitter uses a few different XML feeds to send and receive data from a given user, some feeds require a user name and password supplied through Curl but a few are publicly available to all.
This example will use the built in SimpleXML functions which come with PHP5, this is a much faster and easier way to using alternative readers such as simplePie or anything else you might come across. As far as it goes I don’t think SimpleXML gets enough coverage so I am happy to put it to some use for this example.
Keeping it basic
$user = ‘adi182′;
echo ‘<a href=”http://www.twitter.com/’.$user.’”>Follow ‘.$user.’</a><br />’;
$xml = simplexml_load_file(“http://search.twitter.com/search.atom?q=from:”.$user.”&rpp=5″);
foreach($xml->entry as $tweet)
{
echo $tweet->title. “<br />”;
}
?>
So there you have it, the super simple example on putting a Twiter feed on your website.
Javascript is probably the most awesome tool a web developer can use to make a website both functional and look nice. Javascript has also evolved over the years with the DOM it has become much easier to develop.
One useful piece of code I always end up using when writing Javascript is getElementById, the way Javascript evolved has given it much more compatibility with different browsers and in turn means you need less code to do more.
getElementById allows you to modify any html element with a given ID. so for example if you have a <div> with the ID jstest it might look like this
<div id=”jstest”>howdy</div>
Using document.getElementById(‘jstest’) we can modify this element dynamically with javascript changing anything from its appearance or position with styling or use it within our javascript code.
using document.getElementById(‘jstest’).innerHTML we could change or get the contents of the div.
Another pretty awesome use for the getElementById method would be to change the style of an element dynamically, maybe you want it to disappear when clicked or have a border when highlighted.
To change the background of an element we could use document.getelementById(‘jstest’).style.background-color = ‘#dedede’ this will work with any styling you could apply to an element.
If you are like 90% of the old school web developers I know you probably don’t like using javascript but the modern DOM it is couldn’t be easier.
Recent Comments