Hi
I’ve tried to implement a basic twitter display on a few websites, using the following code:
<?php
$username = "iamtheste";
$limit = 1;
$feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;
if ($tweets = file_get_contents($feed)) {
$tweets = str_replace("&", "&", $tweets);
$tweets = str_replace("<", "<", $tweets);
$tweets = str_replace(">", ">", $tweets);
$tweet = explode("<item>", $tweets);
$tcount = count($tweet) - 1;
for ($i = 1; $i <= $tcount; $i++) {
$endtweet = explode("</item>", $tweet[$i]);
$title = explode("<title>", $endtweet[0]);
$content = explode("</title>", $title[1]);
$content[0] = str_replace("–", "—", $content[0]);
$content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" target="_blank">$1$2$4</a>', $content[0]);
$content[0] = str_replace("$username: ", "", $content[0]);
$content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $content[0]);
$content[0] = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content[0]);
$mytweets[] = $content[0];
}
while (list(, $v) = each($mytweets)) {
$tweetout .= "<div id='tweet'>$v</div>\n";
}
} else {
$tweetout = "<div id='tweet'>Our Twitter feed seems to be having trouble at the moment. You can visit our Twitter page <a href='' target='_blank'>here</a>.</div>";
}
?>
And basically it’s returning a HTTP 400 Bad Request error. Now, I’m really not much of a developer at all and I’ve basically managed deduce from reading a few posts on here etc that Twitter limits the amount of requests per hour or something along those lines. Now this ‘Twitter Feed Display’ is on two websites (both sat on the same server - which is shared hosting, which limits what I can do on there somewhat). I’m basically look for the reason it’s throwing up errors and also what I can do to fix it? Any help would be appreciated
Thank you
*EDIT I should point out, I’ve seen the Twitter Widget that allows you to display tweets. But I was ideally after something a could style/design more. Essentially creating my own widget if you like.