I'm trying to get the next page return with cURL.
How do I do this, being the HTTPS protocol?
<?php
//$url = 'https://api.mercadolibre.com/sites/MLB/search/';
$url = 'https://api.mercadolibre.com/sites/MLB/search?category=MLB1648';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CAINFO, getcwd() . DIRECTORY_SEPARATOR . 'cacert.pem');
$output = curl_exec($curl);
curl_close($curl);
header('Content-Type: application/json');
echo $output;
The file cacert.pem
should be downloaded at link and placed in the same folder as the above script .
NOTE: When using the Free Market API, specify MLB to fetch data in the Brazilian version of the site. MLA refers to the Argentine version.
You can also create a function to make it easier:
<?php
function get($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CAINFO, getcwd() . DIRECTORY_SEPARATOR . 'cacert.pem');
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
header('Content-Type: application/json');
// Obtém produtos da categoria "Informática"
echo get('https://api.mercadolibre.com/sites/MLB/search?category=MLB1648');
// Obtém as categorias do site;
echo get('https://api.mercadolibre.com/sites/MLB/categories');
// Faz uma busca com a palavra-chave "pendrive"
echo get('https://api.mercadolibre.com/sites/MLB/search?q=pendrive');