This works, however I keep getting a failed to open stream every so many random refreshes/page views. I've also tried this code on two different hosts with the same results. I've also tried using cURL with the same results. It keeps showing an error on the file_get_contents. Is there a conflict with wordpress and file_get_contents?
function get_tweets($twitter_username, $tweet_count) {
if(($twitter_info = file_get_contents('https://api.twitter.com/1/users/show.json?screen_name=' . $twitter_username)) === FALSE) {
return false;
}
$twitter = array();//store all info in this array
if(($profile_info = @json_decode($twitter_info, true)) === FALSE) {
return false;
}
$twitter['name'] = $profile_info['name'];
$tweets = array();
if(($tweets_json = file_get_contents('https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name='.$twitter_username.'&count='.$tweet_count))) {
if(($all_tweets = @json_decode($tweets_json, true)) === FALSE) {
return false;
}
foreach($all_tweets as $tw) {
$tweets[] = array('tweet'=>make_clickable_urls($tw['text']), 'created_at'=> 'about '. time_since(strtotime($tw['created_at'])) . ' ago', 'profile_image_url'=>$twitter['profile_image_url']);
}
}
else {
return false;
}
$twitter['tweets'] = $tweets;
return $twitter;
}