Example #1
0
 public function current()
 {
     $arguments = $this->arguments;
     $resp = $this->api->get($this->endpoint, $arguments);
     // Check for rate limits
     if (is_array($resp) && isset($resp['errors'], $resp['tts']) && $this->sleep_on_rate_limit) {
         if ($resp['tts'] == 0) {
             TwitterApio::debug("An error occured: " . print_r($resp['errors'], TRUE));
             $this->next_cursor = $this->prev_cursor = 0;
             return array();
         } else {
             TwitterApio::debug("Sleeping for {$resp['tts']}s. ...");
             sleep($resp['tts'] + 1);
             // Retry
             $resp = $this->api->get($this->endpoint, $arguments);
         }
     }
     if ($this->response_array) {
         // Set previous cursor
         if (isset($resp['previous_cursor'])) {
             $this->prev_cursor = $resp['previous_cursor'];
         } else {
             $this->prev_cursor = 0;
         }
         // Set next cursor
         if (isset($resp['next_cursor'])) {
             $this->next_cursor = $resp['next_cursor'];
         } else {
             $this->next_cursor = 0;
         }
         if (isset($resp['ids'])) {
             return $resp['ids'];
         } else {
             return array();
         }
     } else {
         // Set previous cursor
         if (isset($resp->previous_cursor)) {
             $this->prev_cursor = $resp->previous_cursor;
         } else {
             $this->prev_cursor = 0;
         }
         // Set next cursor
         if (isset($resp->next_cursor)) {
             $this->next_cursor = $resp->next_cursor;
         } else {
             $this->next_cursor = 0;
         }
         // Return the result
         if (isset($resp->ids)) {
             return $resp->ids;
         } else {
             return array();
         }
     }
 }
Example #2
0
 public function current()
 {
     $arguments = $this->arguments;
     if (isset($arguments['since_id']) && $arguments['since_id'] <= 0) {
         unset($arguments['since_id']);
     }
     if (isset($arguments['max_id']) && $arguments['max_id'] <= 0) {
         unset($arguments['max_id']);
     }
     $resp = $this->api->get($this->endpoint, $arguments);
     // Check for rate limits
     if (is_array($resp) && isset($resp['errors'], $resp['tts'])) {
         if ($this->sleep_on_rate_limit) {
             if ($resp['tts'] == 0) {
                 TwitterApio::debug("An error occured: " . print_r($resp['errors'], TRUE));
                 $this->max_id = $this->since_id = 0;
                 return array();
             } else {
                 TwitterApio::debug("Sleeping for {$resp['tts']}s. ...");
                 sleep($resp['tts'] + 1);
                 // Retry
                 $resp = $this->api->get($this->endpoint, $arguments);
             }
         } else {
             $this->max_id = $this->since_id = 0;
             return array();
         }
     }
     if ($this->response_array) {
         if (is_array($resp) && !isset($resp['errors']) && !isset($resp['statuses'])) {
             $first_tweet = end($resp);
             $latest_tweet = reset($resp);
         } elseif (isset($resp['statuses'])) {
             // Search results come this way
             $first_tweet = end($resp['statuses']);
             $latest_tweet = reset($resp['statuses']);
             $resp = $resp['statuses'];
         } else {
             $this->since_id = $this->max_id = 0;
             $latest_tweet = $first_tweet = FALSE;
         }
     } else {
         if (is_object($resp) && !isset($resp->statuses)) {
             $first_tweet = end($resp);
             $latest_tweet = reset($resp);
         } elseif (isset($resp->statuses)) {
             // Search results come this way
             $first_tweet = end($resp->statuses);
             $latest_tweet = reset($resp->statuses);
             $resp = $resp->statuses;
         } else {
             $this->since_id = $this->max_id = 0;
             $latest_tweet = $first_tweet = FALSE;
         }
     }
     // Update since_id with the most recent tweet received
     if (is_array($latest_tweet) or is_object($latest_tweet)) {
         $this->since_id = $this->response_array ? $latest_tweet['id'] : $latest_tweet->id;
         if (empty($this->latest_tweet_id)) {
             $this->latest_tweet_id = $this->since_id;
         }
         /* If this is not the first request, remove the latest tweet.
          * We must do this because 'max_id' parameter is inclusive, so the latest tweet is
          * the same as the first one was on the previous request. */
         if ($this->max_id > 0) {
             reset($resp);
             unset($resp[key($resp)]);
         }
     }
     if (is_array($first_tweet) or is_object($first_tweet)) {
         $this->max_id = $this->response_array ? $first_tweet['id'] : $first_tweet->id;
         $this->oldest_tweet_id = $this->max_id;
     } else {
         $this->max_id = 0;
     }
     if ($this->since_id == $this->max_id) {
         $this->max_id = 0;
     }
     if (!empty($resp)) {
         return $resp;
     } else {
         return array();
     }
 }