具有偏移和限制的Box Api GET文件夹项目不起作用

时间:2018-12-19 20:59:10

标签: c# httpwebrequest box

我正在尝试在Box.com 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,好像我根本没有提供任何limitoffset参数一样。这是其中的一小段:

{"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"}]}

这可能是Box.com的api中的错误吗?还是我在api调用中做错了什么?

0 个答案:

没有答案