Skip to main content

Posts

Showing posts with the label twitter

Caching your Twitter feed on your website in PHP

Instead of reinventing the wheel I'm going to copy the script found at css-tricks.com ( click here ) function getTwitterStatus($userid){ $url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1"; $xml = simplexml_load_file($url) or die("could not connect"); foreach($xml->status as $status){ $text = $status->text; } echo $text; } //my user id kenrick1991 getTwitterStatus("kenrick1991"); I'm leaving the original author's Twitter ID in there, but obviously you'll change this to yours. This function will retrieve the most recent Tweet from your feed (see the "count=1" variable in the URL). But it will request this every time the page loads. The most simple caching strategy is to write your Twitter status to disk, and when your page loads check the timestamp of the file against the value returned by time(). If it exceeds whatever threshold you deem appropriate you ...