从Outlook Office REST API获取联系人计数-Javascript [英] Getting a Count of Contacts from Outlook Office REST API - Javascript

查看:189
本文介绍了从Outlook Office REST API获取联系人计数-Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难区分Microsoft数量众多的冲突API文档:outlook.office.com,outlook.office365.com,microsoft graph,Azure等

I'm having difficulty distinguishing between Microsoft's absurd amount of conflicting API documentations: outlook.office.com, outlook.office365.com, microsoft graph, Azure, and so on

我已经成功验证并拉出了联系人,但是似乎无法计数何时停止分页.

I've successfully authenticated and pulled contacts, but I can't seem to get a count to know when I should stop pagination.

我一直在使用:

Access Token url: 
    https://login.microsoftonline.com/common/oauth2/v2.0/token;
Successful Contact url: 
    https://outlook.office.com/api/v2.0/me/contacts;

他们的 REST API资源说,我应该能够简单地调用https://outlook.office.com/api/v2.0/me/contacts/$count,但这将始终返回正文为-1的纯文本MIME类型.

Their REST API Resource says I should be able to simply make a call to https://outlook.office.com/api/v2.0/me/contacts/$count but this keeps returning a plaintext MIME type with body -1.

如果有人以前曾为此苦苦挣扎或知道发生了什么,我将向正确的方向表示感谢,并希望为您提供一些简单的建议!

If anyone has struggled with this before or knows what's going on, I'd appreciate a point in the right direction - and hopefully some easy points for you!

编辑:感谢以下Jason的有益支持.使用沙箱,我可以通过以下方式重现该问题:

EDIT: Thanks to Jason below for his helpful support. Using the sandbox I was able to reproduce the issue with the following:

登录到我的帐户->收到访问令牌->对https://outlook.office.com/api/v2.0/me/contacts/$count

Logged in to my account -> Received Access Tokens -> Made a GET call to https://outlook.office.com/api/v2.0/me/contacts/$count

请求标头:

GET https://outlook.office.com/api/v2.0/me/contacts/$count HTTP/1.1
Accept: text/*, application/xml, application/json; odata.metadata=none
User-Agent: PlayGroundAgent/1.0
Authorization: Bearer [standard-access-token]
client-request-id: 8f605[client-id-obscured-for-security]7289
X-AnchorMailbox: [email-address-removed-for-security on stackOverflow]

回复

HTTP/1.1 200 OK
Transfer-Encoding: chunked
request-id: de95eaa8-95a7-40bb-b0f9-ced7270f0433
X-CalculatedBETarget: SN1PR05MB1998.namprd05.prod.outlook.com
X-BackEndHttpStatus: 200
OData-Version: 4.0
X-DiagInfo: SN1PR05MB1998
X-BEServer: SN1PR05MB1998
X-FEServer: SN1PR0501CA0035
X-MSEdge-Ref: Ref A: 657E0491C29D46978D8DD3B01B9F93A3 Ref B: DDDD64A109F4E842A8213F038BFDD5FA Ref C: Fri Aug 19 09:20:05 2016 PST
Cache-Control: private
Date: Fri, 19 Aug 2016 16:20:05 GMT
Set-Cookie: exchangecookie=6ca5fc4df96e458e8b879de61aa574ef; expires=Sat, 19-Aug-2017 16:20:05 GMT; path=/; HttpOnly
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

-1


第二次编辑:即使返回了有效的联系人数组,看起来https://outlook.office.com/api/v2.0/me/contacts?$count=true也会返回@odata.count": -1.


2nd Edit: It looks like https://outlook.office.com/api/v2.0/me/contacts?$count=true returns @odata.count": -1 as well, even as it returns valid array of contacts.

第三次工作版本(上述错误使用相同的方法) 网址: https://outlook.office.com/api/v2.0/我/联系人/ $ count

3rd Working version (Same method was used as the errors above) Url: https://outlook.office.com/api/v2.0/me/contacts/$count

请求标头:

GET https://outlook.office.com/api/v2.0/me/contacts/$count HTTP/1.1
Accept: text/*, application/xml, application/json; odata.metadata=none
User-Agent: PlayGroundAgent/1.0
Authorization: Bearer [access-token]
client-request-id: a7954db3-[client-id]-7a6e2e74dd9c
X-AnchorMailbox: [same-email-as-above]

响应:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
request-id: 8c5db16b-3023-4968-9bdc-3d5ecac12ecb
X-CalculatedBETarget: SN1PR05MB1998.namprd05.prod.outlook.com
X-BackEndHttpStatus: 200
OData-Version: 4.0
X-DiagInfo: SN1PR05MB1998
X-BEServer: SN1PR05MB1998
X-FEServer: SN1PR0501CA0019
X-MSEdge-Ref: Ref A: 0574E46DB720491FBCEF23B73428F191 Ref B: FA4529229719F069B9D019E4D53E9200 Ref C: Fri Aug 19 09:42:55 2016 PST
Cache-Control: private
Date: Fri, 19 Aug 2016 16:42:55 GMT
Set-Cookie: exchangecookie=63a1de916a4c48be88569f05ce0361a7; expires=Sat, 19-Aug-2017 16:42:55 GMT; path=/; HttpOnly
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

29

希望这些帮助!

推荐答案

很抱歉得知您遇到了麻烦!这里发生了几件事.

Sorry to hear that you're having trouble! There's a couple of things going on here.

令人困扰的是,您从$count通话中获得了一个负数.如果您访问 https://oauthplay.azurewebsites.net 并使用您的帐户登录,是否会得到相同的结果从那个电话吗?

It's troubling that you're getting a negative number back from the $count call. If you go to https://oauthplay.azurewebsites.net and login with your account, do you get the same result from that call?

对于分页,如果您只想获取所有结果,则最好不要依赖$count值.相反,您应该使用响应中返回的@odata.nextLink值来获取下一页.当然,如果要在获得所有结果之前尝试向用户指示有多少页,那么$count是做到这一点的方法.

For paging, if all you want to do is get all the results, it is better to not rely on the $count value. Instead, you should use the @odata.nextLink value that comes back in the response to get the next page. Of course if you're trying to indicate to a user how many pages are there before getting all the results, the $count is the way to do that.

分页由页面大小($top参数)和光标"($skip parameter). If you're making a call to/me/contacts with no parameters, then you're getting the default page size of 10 and default cursor of 0. You can use the $ top`参数)控制,以请求每页更多结果.

Paging is controlled by the page size (the $top parameter) and the "cursor" (the $skip parameter). If you're making a call to/me/contactswith no parameters, then you're getting the default page size of 10 and default cursor of 0. You can use the$top` parameter to request more results per page.

@odata.nextLink值将始终返回一个URL,您可以根据您在$top中指​​定的页面大小(如果未指定,则为10)来获取下一页.这是执行GET https://outlook.office.com/api/v2.0/me/contacts的值:

The @odata.nextLink value will always return a URL you can use to get the next page based on the page size you specified in $top (or 10 if you did not specify). Here's the value from doing GET https://outlook.office.com/api/v2.0/me/contacts:

"@odata.nextLink": "https://outlook.office.com/api/v2.0/me/contacts/?%24skip=10"

这会跳过10个结果(基于默认的页面大小10).

This skips you ahead 10 results (based on the default page size of 10).

这是GET https://outlook.office.com/api/v2.0/me/contacts/?$top=20中的值:

"@odata.nextLink": "https://outlook.office.com/api/v2.0/me/contacts/?%24top=20&%24skip=20"

如果没有更多页面,则@odata.nextLink值将不会出现在响应中.因此,您可以将其用作停止分页的指示器.

If there are no more pages, the @odata.nextLink value will not be present in the response. So you can use that as your indicator to stop paging.

这篇关于从Outlook Office REST API获取联系人计数-Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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