首页 > 解决方案 > 如何按 conversationId 过滤消息

问题描述

我正在尝试获取属于对话的消息列表。

            var conversationMessages = await client.Me.Messages
                .Request()
                .Filter($"startsWith(conversationId, '{message.ConversationId}')")
                .Select(m => new { m.ConversationId })
                .GetAsync().ConfigureAwait(false);

这给出了错误消息

包含过滤器只能用于字符串属性。

我不明白这个错误信息,因为 conversationId 是一个字符串。

根据另一个问题的答案,我认为startsWithequalsor替换eq可能会起作用。这会更好,因为我要检查的是平等。但后来我得到

过滤子句无效

表示equals尚不支持。

标签: c#microsoft-graph-api

解决方案


我已经在Graph Explore中对其进行了测试,它对我来说效果很好。我已经给出了 HTTP 调用 -https://graph.microsoft.com/v1.0/me/messages?$filter=conversationId eq 'AAQkAGI0Mjk2NTQ5LTE4MjctNDE1Yy04Nzc0LWIxNzA0MDBkNDkwZAAQADdMKw2knP9Pj1rq9BpHpsc='

在此处输入图像描述

所以试试下面的代码。

var conversationMessages = await client.Me.Messages
                .Request()
                .Filter("conversationId eq 'messageConverstaionid'")
                .GetAsync();

推荐阅读