I have a twitter feed in the sidebar of my magento built site, the following PHP calls to the twitter API and posts the feed as a list:
<?php
$feedUrl = 'https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=ecpublish&count=4';
$feedXml = file_get_contents($feedUrl);
try {
$feedXml = new SimpleXMLElement($feedXml);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
<ul>
<?php foreach($feedXml[0]->channel->item as $elName => $child): ?>
<li>
<a href="<?php echo (string)$child->link; ?>" title="" target="_blank"><?php echo substr((string)$child->title, 11); ?></a>
</li>
<?php endforeach ?>
</ul>
Unfortunately I'm getting an error in my system.log that reads as follows:
2012-12-04T01:02:33+00:00 ERR (3): Warning: file_get_contents(https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=ecpublish&count=4) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /clientdata/apache-www/e/c/ecpublishing.com.au/www/app/design/frontend/default/ecp/template/page/sidebar/twitter.phtml on line 9
I have tried fixes such as urlencode(), cURL, checked PHP version and fopen status, nothing is helping me out. I have a feeling it may be due to the twitter rate limiting: https://dev.twitter.com/docs/rate-limiting but can't work out why this would be.
My site is: http://ecpublishing.com.au