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?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.