Worked with XML feeds before, but this one seems to be causing an error.
I am not experienced so please be gentle.
The following code should load in a Twitter feed using its XML address. And it does 20% of the time. The other times it returns in error. I have no idea why.
<?php
if(simplexml_load_file('https://api.twitter.com/1/statuses/user_timeline/quitecheesedoff.xml?count=6')) {
$xml = simplexml_load_file('https://api.twitter.com/1/statuses/user_timeline/quitecheesedoff.xml?count=6');
$tweets = $xml->xpath("/statuses/status");
foreach($tweets as $tweet) {
$text = $tweet->text;
$date = $tweet->created_at;
echo '<div class="tweet"><b>' . $text . '</b>' . $date . '</div>';
}
}
else echo 'error';
?>
Error
Warning:
simplexml_load_file(https://api.twitter.com/1/statuses/user_timeline/quitecheesedoff.xml?count=6)
[function.simplexml-load-file]: failed to open stream: HTTP request
failed! HTTP/1.0 400 Bad Request in
You’re probably making too many requests, triggering the hourly request limit of 150 – which becomes 75 with your code.
I’d recommend using
instead. Your
$xml = ...line is then not required anymore.Update:
The 400 error isn’t always actually used for bad requests at Twitter. Since it works 20% of the time I’d say it’s safe to say there’s something else.
https://api.twitter.com/1/statuses/user_timeline.xml?count=6&screen_name=quitecheesedoffinstead.In the past the 400 error was also given when Twitter’s internal proxies made mistakes.