且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更新邮件类别.正在获得“空有效负载.调用Microsoft Graph时出现“预期的JSON内容"错误

更新时间:2023-11-27 16:23:46

您正在使用Graph Client SDK是一种绕行的方式,比其他任何方式都更可能使您头疼.还会导致不必要的复杂代码.

You're using the Graph Client SDK is a rather roundabout way which is more likely going to cause you headaches than anything else. It also leads to more complicated code than necessary.

SDK包含了整个请求所需的一切.除了边缘情况外,您永远不需要处理HttpProvider实例或管理HttpRequestMessageHttpResponseMessage实例.

The SDK includes everything you need for the entire request. With the exception of an edge case, you should never need to deal with the HttpProvider or manage HttpRequestMessage and HttpResponseMessage instances.

以下将完成相同的事情(设置消息的Categories属性),而复杂度要低得多:

The following will accomplish the same thing (setting the Categories property of a message) with a lot less complexity:

public async void UpdateMailCategory(GraphServiceClient graphClient, string messageId, string inbox)
{
    try
    {
        await graphClient
            .Users[inbox]
            .Messages[messageId]
            .Request()
            .UpdateAsync(new Message()
            {
                Categories = new List<string>() { "Processed" }
            });
    }
    catch (ServiceException Servex)
    {
        throw Servex;
    }
}

此操作也不应使用/beta版本,因为版本支持 .您只需要利用/beta版本来管理用户的类别,因为该尚不可用.

You also shouldn't use the /beta version for this operation as it is supported by the /v1.0 version. You should only need to leverage the /beta version to manage the user's Categories since this isn't generally available yet.