/ Published in: PHP
Nothing revolutionary, just a simple implementation.
A reworking from Brian Cray's source code:
http://briancray.com/2009/08/21/tweeted-links-twitter-api-php-cache/
Note: requires creating a cache file, '/caches/twitter', relative to source.
A reworking from Brian Cray's source code:
http://briancray.com/2009/08/21/tweeted-links-twitter-api-php-cache/
Note: requires creating a cache file, '/caches/twitter', relative to source.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // define the parameters you want to use $username = 'richardmaisano'; $tweet_count = '10'; // define the api url $url = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $count . '&include_entities=1&include_rts=1'; // define the cache file you created // check to see if the cache is older than five minutes // if so, refresh the data if ($cache_time > $five_minutes) { } else { } // set up the json return // the rest of the script just parses through the data, // namely the date and time of tweet and any 'entities' foreach ($json as $tweet) : $datetime = $tweet->created_at; $tweet_text = $tweet->text; // check if any entites exist and if so, replace then with hyperlinked versions foreach ($tweet->entities->urls as $url) { $find = $url->url; $replace = '<a href="'.$find.'">'.$find.'</a>'; } foreach ($tweet->entities->hashtags as $hashtag) { $find = '#'.$hashtag->text; $replace = '<a href="http://twitter.com/#!/search/%23'.$hashtag->text.'">'.$find.'</a>'; } foreach ($tweet->entities->user_mentions as $user_mention) { $find = "@".$user_mention->screen_name; $replace = '<a href="http://twitter.com/'.$user_mention->screen_name.'">'.$find.'</a>'; } } ?> <div class="entry tweet"> <span><?php echo $tweet_text; ?></span> <div class="meta"> <small><?php echo $time; ?>, <?php echo $date; ?></small> </div> </div> <?php endforeach; ?> <?php endif; ?>
URL: http://www.richardmaisano.com/php-json-twitter-api