c# - 通过 Graph API 创建团队时出现 BadRequest 或冲突

标签 c# asp.net-core microsoft-graph-api microsoft-graph-sdks

我的项目正在使用图形 API V.1 版本 3.8.0 和 .NET 核心 3.1 我创建了一个组“标记”向该组添加成员和所有者,一切都很好但是当我创建团队时然后我收到错误 我尝试了两种格式正文,内容如下:

1.第一种格式:

var groups = await graphClient.Groups.Request().GetAsync()
 
var team = new Team 
{
    
MemberSettings = new TeamMemberSettings
    {
        
       AllowCreateUpdateChannels = true
    },
    MessagingSettings = new TeamMessagingSettings
    {
        AllowUserEditMessages = true,
        AllowUserDeleteMessages = true
    },
    FunSettings = new TeamFunSettings
    {
        AllowGiphy = true,
        GiphyContentRating = GiphyRatingType.Strict
    }
};

await graphClient.Groups[groups.Id].Team.Request().PutAsync(team);

I have reference from [1]: https://learn.microsoft.com/en-us/graph/api/team-put-teams?view=graph-rest-1.0&tabs=csharp

结果:状态代码:BadRequest

Microsoft.Graph.ServiceException: Code: BadRequest
Message: Bad Request

Inner error:
        AdditionalData:
        date: 2020-07-15T22:49:41
        
request-id: 865a9ce7-21ea-4a3e-bbc4-88fb7f88b7ca

ClientRequestId: 865a9ce7-21ea-4a3e-bbc4-88fb7f88b7ca

2.second Format I added field : ODataType = null

var groups = await graphClient.Groups
                          .Request()
                          .GetAsync();

Team team = new Team

            {
                MemberSettings = new TeamMemberSettings
                {
                    AllowCreateUpdateChannels = true,
                    ODataType = null
                },
                MessagingSettings = new TeamMessagingSettings
                {
                    AllowUserEditMessages = true,
                    AllowUserDeleteMessages = true,
                    ODataType = null
                },
                FunSettings = new TeamFunSettings
                {
                    AllowGiphy = true,
                    GiphyContentRating = GiphyRatingType.Strict,
                    ODataType = null
                },
                ODataType = null
            };

            await graphClient.Groups[groups.Id].Team
                .Request()
                .PutAsync(team);

结果:状态代码:冲突

Microsoft.Graph.ServiceException: Code: Conflict

Message: Conflict

Inner error:
        AdditionalData:
        date: 2020-07-15T22:49:36
        request-id: a218abee-c090-4a70-a072-ab33db5486dd

ClientRequestId: a218abee-c090-4a70-a072-ab33db5486dd 

但是当我与 postman 一起运行时,结果成功,格式为 2 我不明白为什么当我使用 ASP .Net 语句时结果返回错误??请支持我如何修复。谢谢

最佳答案

我解决了这个问题,我没有使用 SDK Graph API,我使用 HttpClient 调用 Create Team API 并且效果很好。

关于c# - 通过 Graph API 创建团队时出现 BadRequest 或冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62925228/

相关文章:

c# - ObjectDataSource 使用带有构造函数的服务类

c# - 如何更改数据表中日期列的日期格式?

使用 Npgsql for Postgresql 的 C# 查询显示重复的结果和缺失的表数据

c# - 从 Action 过滤器中查看模型

microsoft-graph-api - Microsoft Graph People API - 获取请求/me/people/{id} 时出错

c# - 具有完整对象访问权限的 LINQ Group-by

.net - TempData 在哪里存储它的数据?

C# - Blazor @onlick 如何单击 HTML 元素

oauth-2.0 - 如何使用 MailKit 中的 OAuth 2.0 连接到 Exchange Online?

microsoft-graph-api - 通过objectids获取多个用户/组