Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ///
- // Raw, standalone PHP file
- ///
- function rawTwitterCache_cacheTweets() {
- require_once("twitteroauth/twitteroauth.php");
- $userName = (isset($_REQUEST['username'])) ? $_REQUEST['username'] : '';
- $tweetCount = (isset($_REQUEST['count'])) ? $_REQUEST['count'] : '';
- $consumerKey = 'CONMSUMER_KEY';
- $consumerSecret = 'SHH_CONSUMER_SECRET';
- $accessToken = '_ACCESS_TOKEN';
- $accessTokenSecret = 'QUIET!_TOKEN_SECRET';
- $connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
- if ($userName) {
- $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $userName . "&count=" . $tweetCount);
- }
- echo json_encode($tweets);
- }
- rawTwitterCache_cacheTweets(); // Returns JSON object of tweets
- ///
- // Virtually Wordpress function
- ///
- function vnmTwitterCache_cacheTweets() {
- require_once("twitteroauth/twitteroauth.php");
- $userName = get_option('vnmTwitterCache_twitterName');
- $tweetCount = get_option('vnmTwitterCache_tweetCount');
- $consumerKey = get_option('vnmTwitterCache_consumerKey');
- $consumerSecret = get_option('vnmTwitterCache_consumerSecret');
- $accessToken = get_option('vnmTwitterCache_accessToken');
- $accessTokenSecret = get_option('vnmTwitterCache_accessTokenSecret');
- $connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
- if ($userName) {
- $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $userName . "&count=" . $tweetCount);
- }
- $jsonArray = array();
- $jsonArray['response'] = $tweets;
- echo json_encode($jsonArray);
- die();
- }
- add_action('wp_ajax_cacheTweets', 'vnmTwitterCache_cacheTweets'); // Call to 'cacheTweets' via Ajax, scheduled event or similar returns JSON object with message: 'Sorry, that page does not exist'
- ?>
Advertisement
Add Comment
Please, Sign In to add comment