Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mathiasschopmans/606515 to your computer and use it in GitHub Desktop.
Save mathiasschopmans/606515 to your computer and use it in GitHub Desktop.
A little Script that gets the latest Tweets and chaches it via Transient-API
/**
* Get the latest Tweet Text by Username
*
* @uses Transient - API for chaching
* @copyright Mathias Schopmans - 10/2010
*
* @param string $username: Twitter Username
*/
function get_last_tweet($username='nasenmann'){
if (false === ($last_tweet = get_transient('last_tweet_by_'.$username))) {
$res = wp_remote_get('http://twitter.com/statuses/user_timeline/'.$username.'.json');
$tweets = json_decode($res['body']);
foreach ($tweets as $tweet){
if(empty($tweet->in_reply_to_user_id)){
$last_tweet = $tweet->text;
break;
}
}
set_transient('last_tweet_by_'.$username, $last_tweet, 10*60);
}
return $last_tweet;
}
print_r(get_last_tweet());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment