首页 文章

使用Microsoft OneDrive API / SDK进行客户端分页

提问于
浏览
6

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

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

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

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

{
  "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实现吗?

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

1 回答

  • 1

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

    OneDrive的分页模型与跳过略有不同 . 基本上你会做一个查询:GET https://graph.microsoft.com/v1.0/me/drive/root/children?$top=5在响应中你应该看到通常的值数组,使用名为@ odata.nextLink的属性 . 您将要使用该URL请求下一页:“@ odata.nextLink”:“https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD”获取https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD您一直这样做,直到您没有返回@ odata.nextLink .

相关问题