【发布时间】:2021-05-06 18:30:02
【问题描述】:
我目前正在开发 Laravel / VueJS SPA,我正在发出 GET(通过 file_get_contents)请求以接收来自 3rd 方 API 的订单。一切都按预期工作,除了我只收到 100 个订单(限制?)。目前第 3 方 API 中有 1.064 个订单,但这一数字每天都在增加。
我如何获取并显示所有订单而不是仅显示最后 100 个订单,以及处理如此数量的交易量的最佳方式是什么?我想显示所有订单,因为我目前正在显示 100 很快就会失控。这可以通过例如分页来完成,还是我必须将数据存储在数据库中?
我的 GET 澄清:
private static function makeRequest($method, $endpoint)
{
$username = $_ENV['API_KEY'];
$url = "https://foo.foo.com//api/v1";
// Create a stream
$options = array(
'http' => array(
'method' => $method,
'header' => "Authorization: Basic " . base64_encode("$username:"),
'user_agent' => "foo(foo.foo.com/api - john@doe.com)"
)
);
$context = stream_context_create($options);
return file_get_contents("$url/$endpoint", false, $context);
}
非常欢迎您提供有关如何进行操作的提示!
【问题讨论】:
-
当你通过浏览器或邮递员访问get api的数据时,你得到了所有的订单吗?或者有数百个你可以在流中使用 guzzle 获取大数据。另请注意,如果您不发送任何 API,它们会根据您想要的数量发送数据,默认情况下它们会发送固定值。检查您的 api 是否相同
-
谢谢,确实是这样!该 api 的固定长度为 100 个订单,只是记录不佳。我将不得不使用偏移量
标签: php laravel get-request