I’m at a logical roadblock on how to implement something I’m doing. I’m working with the Instagram API(not important to this question) and in their JSON response they give you 20 results and a link to the next 20 results. I’m trying to build an OOP library that can get the response from the initial API call, search if it has a “next_url” value, and if it does, get the next 20 responses and so un until there’s no longer an next URL. I can’t quite gather the logic on how to do this…
currently here’s the code to get the the first 20…
function __apiCall($url, $post_parameters = FALSE) {
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $url);
if($post_parameters !== FALSE) {
curl_setopt ($curl_session, CURLOPT_POSTFIELDS, $post_parameters);
}
// Return the curl results to a variable
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, $this->codeigniter_instance->config->item('instagram_ssl_verify'));
$contents = curl_exec ($curl_session);
curl_close ($curl_session);
$return = json_decode($contents);
return $return;
}
and here’s a snippet from the JSON response….
stdClass Object
(
[pagination] => stdClass Object
(
[next_url] => https://api.instagram.com/v1/locations/3937885/media/recent?min_timestamp=&min_id=&max_timestamp=&access_token=xxxxxxxxxxxx49414762bea69258210d8872&max_id=133226850290424667_21341717
[next_max_id] => 133226850290424667_21341717
)
[meta] => stdClass Object
(
[code] => 200
)
[data] => Array
(
[0] => stdClass Object
(
[tags] => Array
(
)
[type] => image
[location] => stdClass Object
(
[latitude] => 39.95022
[name] => Neiman Group
[longitude] => -75.168322
[id] => 3937885
)
[comments] => stdClass Object
(
[count] => 0
[data] => Array
(
)
)
BTW. Why are you using two underscores in the name of your
__apiCallfunction. That makes me think something magical is happening.