simplexml - HTTP request failed when using Twitter API with simplexml_load_file -
i want display 5 last tweet of twitter account in list
if(($xml = simplexml_load_file('http://api.twitter.com/1/statuses/user_timeline.xml?count=5&screen_name=les_sismo')) !== false) { $tweets = $xml->xpath("/statuses/status"); foreach($tweets $tweet) { $text = $tweet->text; echo '<li>' . $text . '</li>'; } } else echo 'error';
and got 2 warning
warning: simplexml_load_file(http://api.twitter.com/1/statuses/user_timeline.xml?count=5&screen_name=les_sismo) [function.simplexml-load-file]: failed open stream: http request failed! http/1.0 400 bad request in /homez.466/sismodes/www/wp-content/themes/sismo/header.php on line 89 warning: simplexml_load_file() [function.simplexml-load-file]: i/o warning : failed load external entity "http://api.twitter.com/1/statuses/user_timeline.xml?count=5&screen_name=les_sismo" in /homez.466/sismodes/www/wp-content/themes/sismo/header.php on line 89 error
twitter has pretty strict limit on api calls, if you've exceeded limit you'll 400 bad request error. more info on see: rate limiting faq
to around check http header positive response.
$url = "http://twitter.com/statuses/user_timeline/les_sismo.xml?count=5"; $url_headers = @get_headers($url); if($url_headers[0] == 'http/1.1 200 ok') { $xml = simplexml_load_file($url); } else { // error exit("failed load xml"); }
to around periods xml not accessible due insufficient available api calls, perhaps cache xml file locally , call on fallback in else statement above.
Comments
Post a Comment