Created
October 1, 2010 17:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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