我正在尝试检索盒子网api(并使用偏移量/分页限制)。
根据
the docs
curl https://api.box.com/2.0/folders/FOLDER_ID/items?limit=2&offset=0 \
-H "Authorization: Bearer ACCESS_TOKEN"
这看起来很简单。我相信我是严格遵守这些指示的,我的代码如下:
var boxUrl = "https://api.box.com/2.0/folders/" + folderId + "/items";
var requestParams = new NameValueCollection();
requestParams.Add("limit", "10");
requestParams.Add("offset", "50");
var array = (from key in requestParams.AllKeys
from value in requestParams.GetValues(key)
select string.Format("{0}={1}", key, value))
.ToArray();
var queryString = string.Join("&", array);
var url = boxUrl + "?" + queryString;
WebRequest request = WebRequest.Create(boxEmailUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("Authorization", "Bearer " + AccessToken);
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
当我调试此代码时,值
url
https://api.box.com/2.0/folders/347534773457/items?limit=10&offset=50
这似乎是完全正确的。但我得到的回复是前100张,而不是50-60张。事实上,我从这个api调用中得到的元数据显示
"offset":0, "limit":100
,好像我没有提供任何
limit
或
offset
所有的参数。下面是其中的一个小片段:
{"total_count":101,"entries":[
{"type":"folder","id":"493...
...917","sequence_id":"0","etag":"0","name":"xxxxxxx"}],
"offset":0,"limit":100,"order": [{"by":"type", "direction":"ASC"},{"by":"name","direction":"ASC"}]}
这可能是一个窃听器吗盒子网的api?或者我在api调用中做错了什么?