php - For loop doesnt bring me all results
one text
I have a script that make calls to one api. This api have offset and limit in uri.
Im trying to bring all results, but when i call only bring me until offset 100, but i have a 500 offset. At first i throught it was a limitation of api, but i read the documentation and dont talk about a limitation to response, with exception of the limit.
There is my call code:
For($i=0 ; $offset < $request; $i++){
$offset = $limit*$i;
$url_no = "https://".$account['baseuri']."/messaging_history/api/account/".$account['id']."/conversations/search?offset=".$offset."&limit=".$limit;
$url = "https://".$account['baseuri']."/messaging_history/api/account/".$account['id']."/conversations/search";
$args = array();
# | Cria?�??o do Token e ConsumerSet:
$consumer = new OAuthConsumer($account['consumerKey'], $account['consumerSecret']);
$token = new OAuthToken($account['token'], $account['tokenSecret']);
# | Montando a signature de autentica?�??o:
$request = OAuthRequest::from_consumer_and_token($consumer, $token,"POST", $url_no, $args);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $token);
# | Configurando a URI:
$url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
$ch = curl_init();
# | Adicionando o cabe?�alho da request:
$headers = array($request->to_header());
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url_no);
curl_setopt($ch, CURLOPT_POST, 1 );
# | Corpo da request:
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"start":{"from":'.$from.',"to":'.$to.'},"contentToRetrieve":["sdes"]}' ); //olhar manual php pegar o from e o to por vari??vel mktime;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$resultadofinal = curl_exec($ch); // Execu?�??o da request;
curl_close($ch); // Fechando o Curl;
# | Resposta da request:
$MensagensHistoricas = json_decode($resultadofinal, true);
# | Estruturando o output:
echo "<pre>";
echo "offset:" . $offset . "limit:" . $limit;
echo "</pre>";
$Data = array_column($MensagensHistoricas['conversationHistoryRecords'], 'info');
$frompage = date('d F Y',strtotime("-1 days"));
$topage = date('d F Y');
# Per?�odo do relat??rio apresentado
echo "Dados de " . $frompage . " a " .$topage;
foreach($Data as $PropData) {
echo "<pre>";
print_r("AgentID: ".$PropData['latestAgentId']." | Nome do agente: ".$PropData['latestAgentFullName']." | Skill: ".$PropData['latestSkillName']."| ID da conversa: ".$PropData['conversationId']. " | Dura?�??o: ".($PropData['duration']/60000)); // etc...
echo "</pre>";
}
sleep(1); // Espera 1 segundo antes de executar o script de novo
}
When i try to show only offset, the call works well:
$request = 509;
$offset = 0;
For($i=0 ; $offset < $request ; $i++){
$limit = 100;
$offset = $limit*$i;
echo "<pre>";
echo $offset . " " . $limit;
echo "</pre>";
}
Can anyone help me pls?
Source