<?php require_once 'api/codebird/codebird.php'; require_once 'api/Tweets.php'; require_once 'api/config.php'; $tweets = new Tweets($CONSUMER_KEY, $CONSUMER_SECRET, $ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); $timeline = $tweets->user_timeline(); $hashtag = $tweets->hashtag(); header('Content-type: application/json'); echo $json = isset($_GET['hashtag']) ? $hashtag : $timeline;
{ // Twitter OAuth library: https://github.com/mynetx/codebird-php require_once '../codebird.php'; // Twitter OAuth Settings: $CONSUMER_KEY = ''; $CONSUMER_SECRET = ''; $ACCESS_TOKEN = ''; $ACCESS_TOKEN_SECRET = ''; // Get authenticated: \Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); // Retrieve posts: $username = strip_tags(trim($_GET['username'])); $count = strip_tags(trim($_GET['count'])); // API Settings: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline $params = array('screen_name' => $username, 'count' => $count); // Make the REST call: $data = (array) $cb->statuses_userTimeline($params); unset($data['httpstatus']); unset($data['rate']); foreach ($data as $tweet) { $tweets[] = array('username' => $tweet->user->screen_name, 'profile_image' => $tweet->user->profile_image_url, 'text' => $tweet->text, 'created' => $tweet->created_at); } // Output result in JSON: return json_encode($tweets); } } header('Content-type: application/json'); echo Tweets::user_timeline();
{ public static function hashtag() { // Twitter OAuth library: https://github.com/mynetx/codebird-php require_once '../codebird.php'; // Twitter OAuth Settings: $CONSUMER_KEY = ''; $CONSUMER_SECRET = ''; $ACCESS_TOKEN = ''; $ACCESS_TOKEN_SECRET = ''; // Get authenticated: \Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); // Retrieve posts: $q = strip_tags(trim($_GET['q'])); $count = strip_tags(trim($_GET['count'])); // API Settings: https://dev.twitter.com/docs/api/1.1/get/search/tweets $params = array('q' => $q, 'count' => $count); // Make the REST call: $data = (array) $cb->search_tweets($params); unset($data['search_metadata']); unset($data['httpstatus']); unset($data['rate']); // Output result in JSON: return json_encode($data); } } header('Content-type: application/json'); echo Tweets::hashtag();