本文介绍了使用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.

列表项链接,提到我们可以使用此处.基于此假设,我正在如下构建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:

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

GET 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/驱动器/根目录/孩子?$ 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的客户端分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:25
查看更多