不幸的是,您不得不繼續請求下一頁,直到沒有任何返回,然後合併所有結果。
在我們的內部應用程序,我們有以下功能(在PHP)
/**
* Get pages of data with passed url
* @param [string] $url The api endpoint
* @return [array] All your data
*/
function getPagedData($url) {
// Get all the projects in active collab
$page = 1;
$paged_records = array();
$paged_records_results = $this->activeCollabClient->get($url . '?page=' . $page)->getJson();
$paged_records = array_merge($paged_records, $paged_records_results);
// Loop through pages
while ($paged_records_results = $this->activeCollabClient->get($url . '?page=' . ++$page)->getJson()) {
$paged_records = array_merge($paged_records, $paged_records_results);
}
return $paged_records;
}
然後,它可以調用,傳遞的URL。在你的情況下,它可以像這樣使用:
getPagedData('whats-news/daily');
然後,您將得到一個包含所有信息的數組。