API 요청을하려고합니다. 문제는 결과 집합에 50 개가 넘는 레코드가있는 경우입니다. API는 결과를 각각 50 개의 '페이지'로 나눕니다. 나는 데이터베이스에 저장하기 전에 모든 결과를 가진 단일 배열을 얻으려고합니다.PHP와 컬 : 여러 페이지 컬 요청에서 모든 결과 얻기
<?
$url = 'http://developer-api.bringg.com/partner_api/users';
$data_string = array(
'access_token' => "<YOUR ACCESS TOKEN>",
'timestamp' => date('Y-m-d H:i:s'),
'company_id' => <YOUR COMPANY ID>,
'page' => 3 //this is the page key that needs to be specified
);
$secret_key = "<YOUR SECRET KEY>";
$signature = hash_hmac("sha1", http_build_query($data_string),
$secret_key);
$data_string["signature"] = $signature;
$content = json_encode($data_string);
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type:application/json',
'Content-Length: ' . strlen($content))
);
$json_response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status != 200) {
die("Error: call to URL $url failed with status $status, response
$json_response, curl_error " . curl_error($curl) . ", curl_errno " .
curl_errno($curl));
}
curl_close($ch);
$response = json_decode($json_response, true);
?>
나는 그래서 동적으로 페이지 번호를 변경하는 방법을 모르는 한 레코드 수를 알 수 없습니다 : 다음은 내 코드입니다. 여러 요청을 할 수있는 방법이 있나요, 아마도 루프를 사용하여 페이지 번호를 변경 한 다음 모든 결과를 하나의 배열에 저장하십시오. 제발 도와주세요, 나는 배열과 곱슬 곱슬합니다.