简体   繁体   English

PHP curl parse.com参数

[英]PHP curl parse.com parameters

Parse limits it's results to 100. I'd like to set the limit higher so that I can loop through it. 解析将其结果限制为100.我想将限制设置得更高,以便我可以循环它。 Their cURL example is done like 他们的cURL示例就像

curl -X GET \
  -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -G \
  --data-urlencode 'limit=200' \
  --data-urlencode 'skip=400' \
  https://api.parse.com/1/classes/GameScore

I've written my code for cURL in PHP, but unsure how to incorporate the limit and skip. 我在PHP中编写了cURL的代码,但不确定如何合并限制和跳过。 I reviewed documentation here , but unsure of what it matches to. 在这里查看了文档,但不确定它与之匹配的内容。 Here is my code 这是我的代码

$headers = array(
    "Content-Type: application/json",
    "X-Parse-Application-Id: " . $MyApplicationId,
    "X-Parse-Master-Key: " . $MyParseRestMasterKey
);

    $handle = curl_init(); 
    curl_setopt($handle, CURLOPT_URL, $url);
    curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

    $data = curl_exec($handle);
    curl_close($handle);

What they're doing there with command line cURL will make cURL build an URL like 他们用命令行cURL做的事情将使cURL构建一个像这样的URL

https://api.parse.com/1/classes/GameScore?limit=200&skip=400

As explained in the cURL documentation , that's what the -G parameter does, it converts --data arguments (normally destined to define POST fields) into get parameters. 正如cURL文档中所解释的,这就是-G参数的作用,它将--data参数(通常用于定义POST字段)转换为get参数。

The safest/easiest way would be to compose the query string using http_build_query and tack the result of that call to the end of the url you give to CURLOPT_URL . 最安全/最简单的方法是使用http_build_query组合查询字符串,并将该调用的结果添加到您为CURLOPT_URL提供的URL的末尾。 Like this: 像这样:

$parameters = array('limit' => 200, 'skip' => 400); 
$url = $url . '?' . http_build_query($parameters);
...
curl_setopt($handle, CURLOPT_URL, $url);

Of course, if you're certain that your parameters will always be simple integers (not requiring URL encoding), you could also use simple string functions, like this: 当然,如果你确定你的参数总是简单的整数(不需要URL编码),你也可以使用简单的字符串函数,如下所示:

$url = sprintf("%s?limit=%d&skip=%d",$url,$limit,$skip);
...
curl_setopt($handle, CURLOPT_URL, $url);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM