我正在尝试使用 Shopify API 在我的应用中获取 Shopify 商店的所有产品。我有以下代码可以按页面获取所有产品。这个脚本在某个时间点中断了,但我不确定在哪里。我怎样才能制作一个完整的脚本,它可以一次性获取所有产品而不会中断。
这是我迄今为止所拥有的:
$ch = curl_init();
for ($i=1; $i<=1000; $i++)
{
curl_setopt($ch, CURLOPT_URL, "https://API:PASS@store/products.json?page=$i");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$res = curl_exec($ch);
$res=json_decode($res, true);
foreach($res as $products) { // A different example
foreach($products as $product) {
$title=$product['title'];
}
}
sleep(1);
}
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)