使用Office 365邮件API .NET客户端进行OData搜索 [英] OData Search with Office 365 Mail API .NET Client

查看:124
本文介绍了使用Office 365邮件API .NET客户端进行OData搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用OutLook 365 API但使用Outlookservicesclient(在Outlook 365 sdk中找到此nuget

I need to perform an OData query $search = "subject:pizza" using the OutLook 365 API but using the Outlookservicesclient (found the in the outlook 365 sdk, this nuget https://www.nuget.org/packages/Microsoft.Office365.OutlookServices-V2.0/)

请参见 OutLookAPI OData查询参考

这可以使用HttpClient正常使用,但可以使用.NET客户端库,因此似乎无法添加任何非标准查询参数.

This works correctly using an HttpClient but with the .NET client library, its seemingly not possible to add any non-standard query parameters.

即:var messages = await client.Users['mail@me.com'].Messages .Where(m => m.IsRead == false) .Take(50) .ExecuteAsync();

Ie: var messages = await client.Users['mail@me.com'].Messages .Where(m => m.IsRead == false) .Take(50) .ExecuteAsync();

产生以下RequestURI https://outlook.office365.com/api/v2.0/Users('mail%40me.com')/Messages?$filter=IsRead eq false&$top=50并正确执行.

Produces the following RequestURI https://outlook.office365.com/api/v2.0/Users('mail%40me.com')/Messages?$filter=IsRead eq false&$top=50 And executes correctly.

如果尝试以下操作,var query = client.Users['Mail@me.com'].Messages .Context.CreateQuery<Message>("Users('Mail@me.com')/Messages") .AddQueryOption("$search", "subject:pizza");

Whereas if try the following, var query = client.Users['Mail@me.com'].Messages .Context.CreateQuery<Message>("Users('Mail@me.com')/Messages") .AddQueryOption("$search", "subject:pizza");

任何一个返回Exception:Thrown: "Can't add query option '$search' because it begins with reserved character '$'." (System.NotSupportedException) A System.NotSupportedException was thrown: "Can't add query option '$search' because it begins with reserved character '$'."

如果我省略AddQueryOption行,则会收到身份验证错误.

or im getting authentication errors if I omit the AddQueryOption line.

我需要做的所有工作都是作为追加$search=subject:pizza RequestURI!如果不实际使用Rest Client,这似乎是不可能的,因为Outlook Client似乎仅限于内置的Linq方法.

All I need to do as append $search=subject:pizza the RequestURI! This seems impossible without actually using a rest client as the Outlook Client seems limited to built in Linq methods.

添加了以下事实:客户端库没有参考文档,我走到了尽头.有谁知道是否可以通过outlookservicesclient包含$ search?

Added the fact there is no reference documentation for the client library, ive hit a dead end. Does anyone know if its possible to include $search via the outlookservicesclient?

推荐答案

我与OData.NET人员进行了检查,他们已经打开了

I checked with the OData.NET folks, and they've opened an issue on GitHub to track the error adding $search with AddQueryOption. In the meantime, they suggested you could try something like this to make it work:

var query = context.CreateQuery("Users('Mail@me.com')/Messages");
var searchUri = new Uri(query.RequestUri.OriginalString + "?$search=%22subject%3Apizza%22");
var messages =  context.Execute<Message>(searchUri, "Get");

这篇关于使用Office 365邮件API .NET客户端进行OData搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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