API always return same amount of results

php
api

#1

Hello. I have the following code:

Initialization.php

<?php

require_once('TwitterAPIExchange.php');

final class Initialization {

	 private $settings = [];

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
	function __construct() {
		$this->settings = [
    	'oauth_access_token' => "",
    	'oauth_access_token_secret' => "",
    	'consumer_key' => "",
    	'consumer_secret' => ""
		];
	}
	// Getter for variable $settings
	public function getSettings() {
		// PHP requires $this->settings in order to read member variable $settings
		return $this->settings;
	}		
}

ImplementationSearch.php

<?php


require_once('TwitterAPIExchange.php');
require_once('Initialization.php');

final class ImplementationSearch {
	
	 function __construct() {

		$initialization1 = new Initialization();
		$url = 'https://api.twitter.com/1.1/users/search.json';
		$getfield = '?q=employed%20Microsoft';
		$requestMethod = 'GET';
		//var_dump($initialization1->getSettings());
		$twitter = new TwitterAPIExchange($initialization1->getSettings());
		// String result of API 
		$results = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();  
        // Decode String to JSON Object - 'true' is required in order to make it to String array and not STD class     
        $resultsToJson = json_decode($results,true);  
              
        for($i = 0; $i < count($resultsToJson); $i++){
				echo $resultsToJson[$i]['description'];
				echo "<br/>";
		}
        
	}
}

ExecutionSearch.php

<?php
require_once('ImplementationSearch.php');

$implementation1 = new ImplementationSearch();

So either if i search for $getfield = '?q=employed%20Microsoft'; or for $getfield = '?q=Microsoft'; the results are always 20. Any ideas why?


#2

From GET users/search

count - The number of potential user results to retrieve per page. This value has a maximum of 20.

If you want to get more results you will have to implement pagination using the page parameter value.


#3

Hello. Thank you for your answer. Since this the first time i attempt something like that, this is what you mean?

    $getfield = '?q=Working%20at%20Microsoft&page=' . ++$pageCounter;

in a while loop so i get one page for each request every time?


#4

In essence something like that should work.


#5

The only problem is that i am only able (with each app) at least to retrieve only 180 pages each 15 min? Is that correct?


#6

That’s the API rate limit, correct.