我在如何实现我正在做的事情上遇到了一个合乎逻辑的障碍。我正在使用 Instagram API(对这个问题并不重要),在他们的 JSON 响应中,他们为您提供了 20 个结果和指向下一个 20 个结果的链接。我正在尝试构建一个 OOP 库,该库可以从初始 API 调用中获取响应,搜索它是否具有“next_url”值,如果有,则获取接下来的 20 个响应,等等,直到不再有下一个 URL . 我无法完全收集有关如何执行此操作的逻辑...
目前这里是获取前 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;
}
这是 JSON 响应的一个片段......
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
(
)
)