【问题标题】:php curl to get data from url based on total no of recordsphp curl 根据记录总数从 url 获取数据
【发布时间】:2017-02-23 15:02:11
【问题描述】:

我正在连接到 rest api,它一次只给我 50 个结果的 json 数据,我将结果保存在一个变量中,但我想检索 20000 条记录,我想知道如何构建动态 url获取所有数据并将其保存在变量中。

下面是我当前的代码

    $url = "https://org.atlassian.net/rest/api/2/search?jql=project=PS+order+by+key&startAt=0";
    $ch = curl_init();

    $headers = array('Accept: application/json','Content-Type: application/json');


    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    $ch_error = curl_error($ch);

            if ($ch_error) {
            echo "cURL Error: $ch_error";
            } else {
            $json = json_decode($result, true);}

在我的网址中,我有参数来指定我可以从哪个数字返回记录,例如第一个请求将是 startAt=0,第二个将是 startAt=51,thits 将是 startAt=101,或者我可以使用 x = total 这样的公式no of records/50 然后运行 ​​curl x 次并将所有结果保存在变量中或保存所有 json 数组然后合并它。请求你帮助我。

提前致谢

【问题讨论】:

    标签: php arrays json curl jira


    【解决方案1】:

    有一个名为maxResults的查询参数,默认为50。您可以指定更大的数字。

    maxResults (int):要返回的最大问题数(默认为 50)。最大允许值由 JIRA 属性“jira.search.views.default.max”规定。如果您指定的值大于此数字,您的搜索结果将被截断。

    https://docs.atlassian.com/jira/REST/cloud/#api/2/search-search

    【讨论】:

    • 很遗憾,此选项不适用于 jira 的按需版本
    【解决方案2】:

    我为此创建了一个循环并解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      相关资源
      最近更新 更多