使用 Microsoft OneDrive API/SDK 的客户端分页 [英] Client side paging using Microsoft OneDrive API/SDK

查看:31
本文介绍了使用 Microsoft OneDrive API/SDK 的客户端分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Microsoft OneDrive API/SDK 实现客户端分页.为此,我需要获取 API 响应的项目​​总数,并根据传递给 API 的跳过和最大限制值,获取响应.

I am trying to implement client side paging using Microsoft OneDrive API/SDK. For that I need the total count of items as response from the API, and based on the skip and maximum limit value passed to the API, the response should be fetched.

List Items 链接,提到我们可以使用提供的查询字符串来实现这一点 这里.基于这个假设,我正在构建 API 调用的 URL,如下所示:

In the List Items link, it is mentioned that we can achieve this using the query strings provided here. Based on this assumption, I am building the URL for API call as below:

string.Format("https://graph.microsoft.com/v1.0/me/drive/root/children?$skip={0}&$top={1}&$count=true",topValue*page, topValue)

根据上述 URL 中的信息,一切似乎都很好,但我从服务器收到错误请求",错误消息如下所示:

Everything seems to be fine as per the info in the above mentioned URL, but I am getting "Bad Request" from the server with error message as shown below:

{
  "error": {
    "code": "",
    "message": "The query specified in the URI is not valid. Query option 'Skip' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.",
    "innerError": {
      "request-id": "384693d7-65bd-4dc6-8d60-afde68e01555",
      "date": "2017-04-25T10:28:15"
    }
  }
}


{
  "error": {
    "code": "",
    "message": "The query specified in the URI is not valid. Query option 'Count' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.",
    "innerError": {
      "request-id": "2188a06f-10cf-402c-9c49-bd296b9db614",
      "date": "2017-04-25T10:29:05"
    }
  }
}

这可以使用 REST API 或 Microsoft Graph SDK 实现吗?

Can this be achieved using REST APIs or Microsoft Graph SDK?

PS:我看到了 skipToken 的概念,但这不符合我们的要求,因为它不返回总计数并且只支持增量导航.

PS: I saw the concept of skipToken but that won't fit into our requirements as it does not return the total count and only incremental navigation is supported.

推荐答案

看来 OneDrive 工程师已经回答了这个问题 这里:

It appears that a OneDrive engineer has already answered this question here:

OneDrive 的分页模型与 skip+take 略有不同.本质上,您将进行如下查询:

OneDrive's paging model is a little different to skip+take. Essentially you'll make a query like:

获取 https://graph.microsoft.com/v1.0/me/drive/root/children?$top=5

在响应中,您应该会看到通常的值数组,以及带有一个名为@odata.nextLink 的属性.您需要使用该 URL使用它请求下一页:

and in the response you should see the usual array of values, along with a property called @odata.nextLink. You'll want to take that URL use it request the next page:

@odata.nextLink":"https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD"

"@odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD"

获取https://graph.microsoft.com/v1.0/me/驱动器/root/children?$skiptoken=ASDGASGSD

GET https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD

您一直这样做,直到您没有返回 @odata.nextLink.

You keep doing this until you don't get an @odata.nextLink returned.

这篇关于使用 Microsoft OneDrive API/SDK 的客户端分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆