2

我想创建一个特定类别的作业。

在图形资源管理器中,

https://graph.microsoft.com/beta/education/classes/{classId}/assignments

这个请求效果很好。

但在我的 C# 代码中,

var assignInfo = new EducationAssignment
            {

                DisplayName = "test",
                
                DueDateTime = DateTimeOffset.Parse("2020-09-20T18:00:00Z"),
                Instructions = new EducationItemBody
                {
                    ContentType = BodyType.Html,
                    Content = "hi"
                },
                Status = EducationAssignmentStatus.Draft,
                AllowStudentsToAddResourcesToSubmission = true,
                
                AssignTo = new EducationAssignmentClassRecipient
                {

                },
                Grading = new EducationAssignmentPointsGradeType()
                {
                    MaxPoints = 100
                },
                CreatedDateTime = DateTimeOffset.Parse("2020-09-20T12:00:00Z"),
                AssignDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
                AssignedDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
                
                CloseDateTime = null,
                
                AllowLateSubmissions = true
                
            };

             await graphClient.Education.Classes[pClassId].Assignments
                .Request()
                
                .AddAsync(assignInfo);

发生错误:

{"Code: 20132\r\nMessage: The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2020-09-20T07:25:14\r\n\trequest-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n\tclient-request-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\nClientRequestId: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n"}

为什么会这样?我整天都在思考和尝试。

我试过了

 await graphClient.Education.Classes[pClassId].Assignments
                .Request()
                .Header("Content-Type", "application/json")
                .AddAsync(assignInfo);

但是有同样的错误。

如果只请求 displayname 元素,结果是相同的。

权限已处理。EduAssignments.ReadWriteBasic、EduAssignments.ReadWrite.. 等 并且 dll(NuGet pakage) 也在 beta 版本中准备好了。

我提到了这个文件

我迫切需要帮助。谢谢。

4

1 回答 1

0

添加这个assignInfo.ODataType = null;可以解决问题。

于 2021-09-16T14:56:03.797 回答