php 如何显示来自Invision Power board Rest API的所有数据

brccelvz  于 2022-12-28  发布在  PHP
关注(0)|答案(1)|浏览(102)

我希望显示所有数据,但结果仅为第1页的前25个:我想提取所有的下载文件名,例如
获取所有数据的最佳方法是什么

<?php
$communityUrl = 'https://www.example.com/ips4/';
$apiKey = 'c7a349a1629f02cd2855a58d77646f6d';
$endpoint = '/downloads/files';
$endpoint = '/core/members';

$curl = curl_init( $communityUrl . 'api' . $endpoint );
curl_setopt_array( $curl, array(
    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_HTTPAUTH    => CURLAUTH_BASIC,
    CURLOPT_USERPWD     => "{$apiKey}:"
) );
$response = curl_exec( $curl );
?>

我的php代码

<?php
$result_files = json_decode($response , true);

if (is_array($result_files)) {
  foreach ($result_files as $value) {
    if (is_array($value)) {
       foreach ($value as $info) {
          echo $info['title'];
      }
   }
}
?>

上面的代码只显示25个文件。我有150个。怎么做呢?
谢谢

z31licg0

z31licg01#

你有没有看过其他的下载文件,有一个页面默认为25个文件,你必须发送调用来获取每页150个文件。使用perPages属性来声明每页的数量。

page    int     Page number
perPage     int     Number of results per page - defaults to 25

在这里查看了其他命令后,id put perPage = 150在1次调用中收集150个文件。

$endpoint = '/downloads/files/{perPage=150}';

$endpoint = '/downloads/files?perPage=150'

一种或另一种方法将工作,以获得150个结果。
这里是动态版本,如果你以后会先动态地得到多少文件有,然后提取结果文件量:

$endpoint = '/downloads/files?perPage='.$amount

相关问题