加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

office365 – 使用Microsoft OneDrive API / SDK的客户端分页

发布时间:2020-12-14 02:21:31 所属栏目:Windows 来源:网络整理
导读:我正在尝试使用Microsoft OneDrive API / SDK实现客户端分页.为此,我需要项目的总计数作为API的响应,并且基于传递给API的跳过和最大限制值,应该获取响应. 在List Items链接中,提到我们可以使用here提供的查询字符串来实现此目的.基于此假设,我正在构建API调
我正在尝试使用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,"innerError": {
      "request-id": "2188a06f-10cf-402c-9c49-bd296b9db614","date": "2017-04-25T10:29:05"
    }
  }
}

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

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

解决方法

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

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

GET 07001?$top=5

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”:
“07001?$skiptoken=ASDGASGSD”

GET
07001?$skiptoken=ASDGASGSD

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读