<?php
   require_once( 'TwitterAPIExchange.php' );
   require_once( 'prettify.php' );
   require_once( 'display_lib.php' );
   require_once( 'session.php' );
   require_once( 'api-keys.php' );

   date_default_timezone_set('America/Denver');

   $url = 'https://api.twitter.com/1.1/search/tweets.json';
   // change the #string to get a different hashtag
   $getfield = '?q=#worldcup&result_type=recent&count=11';
   $requestMethod = 'GET';
   $twitter = new TwitterAPIExchange($settings);
   $twitter->setGetfield($getfield);
   $twitter->buildOauth($url, $requestMethod);
   // convert the json response into a PHP array and print it
   $response = $twitter->performRequest();
   $array = json_decode($response, true, 512, JSON_BIGINT_AS_STRING);

   if ( @ ! isset( $_SESSION['tweetHistory'] ) ) {
      $_SESSION['tweetHistory'][] = array();
   }

   $allTheTweets = null;

   foreach($array['statuses'] as $tweet => $number) {
      $user = $number['user']['screen_name'];
      $text = $number['text'];
      $id = $number['id'];
      if ( ! in_array( $id, $_SESSION['tweetHistory'] ) ) {
         $_SESSION['tweetHistory'][] = $id;
         $allTheTweets[] = array(
            "user" => '@' . $user,
            "text" => $text,
            "id"   => $id
         );
      }
   }


   $json = json_encode($allTheTweets);
   print_r($json);