无法使用 Graph API v1.0 创建 ToDo 任务
Unable to create ToDo Task using Graph API v1.0
我正在尝试使用 graph api v1.0 的 ToDo Task 功能来使用以下代码创建任务
var result = graphServiceClient.Users[outlookUserId].Todo.Lists[listid].Tasks.Request().AddAsync(todoTask).Result;
但是,我收到以下错误:
Code: invalidRequest Message: A type named 'microsoft.toDo.todoTask'
could not be resolved by the model. When a model is available, each
type name must resolve to a valid type. Inner error: Code:
InvalidModel AdditionalData: date: 2020-11-25T09:41:04 request-id:
39794548-8f63-443e-a8bc-76ad6091dc8d client-request-id:
39794548-8f63-443e-a8bc-76ad6091dc8d ClientRequestId:
39794548-8f63-443e-a8bc-76ad6091dc8d
为了解决上述问题,我将 todoTask 的 odatatype 设置为 null,但出现另一个异常:
Code: invalidRequest Message: A type named
'microsoft.toDo.dateTimeTimeZone' could not be resolved by the model.
When a model is available, each type name must resolve to a valid
type. Inner error: Code: InvalidModel AdditionalData: date:
2020-11-25T09:43:27 request-id: 0780add8-3f17-40c5-a92b-e9e62ad08bf8
client-request-id: 0780add8-3f17-40c5-a92b-e9e62ad08bf8
ClientRequestId: 0780add8-3f17-40c5-a92b-e9e62ad08bf8
为了解决上面的问题,我将类型为 DateTimeZone 的 todoTask 的所有数据成员的 odatatype 设置为 null,但随后出现以下异常:
Code: invalidRequest Message: A type named 'microsoft.toDo.itemBody'
could not be resolved by the model. When a model is available, each
type name must resolve to a valid type. Inner error: Code:
InvalidModel AdditionalData: date: 2020-11-25T09:46:11 request-id:
5bafbcab-5090-47b5-ac8e-8c96ec1d6592 client-request-id:
5bafbcab-5090-47b5-ac8e-8c96ec1d6592 ClientRequestId:
5bafbcab-5090-47b5-ac8e-8c96ec1d6592
为了解决上面的问题,我将 todoTask 主体的 odatatype 设置为 null,但现在我遇到了以下无法解决的异常:
Code: generalException Message: Internal Server Error Inner error:
AdditionalData: date: 2020-11-25T09:48:23 request-id:
f5d52f43-c0b4-425e-83ec-652fadb7abf9 client-request-id:
f5d52f43-c0b4-425e-83ec-652fadb7abf9 ClientRequestId:
f5d52f43-c0b4-425e-83ec-652fadb7abf9
对于我们的应用程序,我们需要创建任务并同步到 outlook,因为这将投入生产,我们不能使用测试版。谁能帮我保存任务。
更新:
这是我如何设置 TodoTask 对象的代码:
var todoTask = new TodoTask();
todoTask.Title = "Subject";
todoTask.DueDateTime = new DateTimeTimeZone() { DateTime = dueDate.Date.ToString()};
todoTask.Status = TaskStatus.NotStarted;
todoTask.Importance = Importance.Normal;
todoTask.Body = new ItemBody
{
Content = "Test",
ContentType = BodyType.Text
};
todoTask.IsReminderOn = true;
todoTask.ReminderDateTime = new DateTimeTimeZone() {
DateTime = reminderTime.Value.ToString() };
todoTask.Extensions = new TodoTaskExtensionsCollectionPage();
todoTask.Extensions.Add(new OpenTypeExtension{
ExtensionName = "TestProperty",
AdditionalData = new Dictionary<string,object>{{"MyProp","MyValue"}}});
设置odatatype为null后,还需要设置TimeZone
属性 for DueDateTime
and ReminderDateTime
.
例如:
var todoTask = new TodoTask();
todoTask.Title = "Subject2";
todoTask.ODataType = null;
DateTime dueDate = DateTime.UtcNow.Date;
DateTime reminderTime = DateTime.UtcNow.Date;
todoTask.DueDateTime = new DateTimeTimeZone() {
TimeZone = "UTC",
ODataType = null,
DateTime = dueDate.Date.ToString()
};
todoTask.Status = TaskStatus.NotStarted;
todoTask.Importance = Importance.Normal;
todoTask.Body = new ItemBody
{
ODataType = null,
Content = "Test",
ContentType = BodyType.Text
};
todoTask.IsReminderOn = true;
todoTask.ReminderDateTime = new DateTimeTimeZone()
{
TimeZone = "UTC",
ODataType = null,
DateTime = reminderTime.Date.ToString()
};
todoTask.Extensions = new TodoTaskExtensionsCollectionPage();
todoTask.Extensions.Add(new OpenTypeExtension
{
ExtensionName = "TestProperty",
AdditionalData = new Dictionary<string, object> { { "MyProp", "MyValue" } }
});
我正在尝试使用 graph api v1.0 的 ToDo Task 功能来使用以下代码创建任务
var result = graphServiceClient.Users[outlookUserId].Todo.Lists[listid].Tasks.Request().AddAsync(todoTask).Result;
但是,我收到以下错误:
Code: invalidRequest Message: A type named 'microsoft.toDo.todoTask' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. Inner error: Code: InvalidModel AdditionalData: date: 2020-11-25T09:41:04 request-id: 39794548-8f63-443e-a8bc-76ad6091dc8d client-request-id: 39794548-8f63-443e-a8bc-76ad6091dc8d ClientRequestId: 39794548-8f63-443e-a8bc-76ad6091dc8d
为了解决上述问题,我将 todoTask 的 odatatype 设置为 null,但出现另一个异常:
Code: invalidRequest Message: A type named 'microsoft.toDo.dateTimeTimeZone' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. Inner error: Code: InvalidModel AdditionalData: date: 2020-11-25T09:43:27 request-id: 0780add8-3f17-40c5-a92b-e9e62ad08bf8 client-request-id: 0780add8-3f17-40c5-a92b-e9e62ad08bf8 ClientRequestId: 0780add8-3f17-40c5-a92b-e9e62ad08bf8
为了解决上面的问题,我将类型为 DateTimeZone 的 todoTask 的所有数据成员的 odatatype 设置为 null,但随后出现以下异常:
Code: invalidRequest Message: A type named 'microsoft.toDo.itemBody' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. Inner error: Code: InvalidModel AdditionalData: date: 2020-11-25T09:46:11 request-id: 5bafbcab-5090-47b5-ac8e-8c96ec1d6592 client-request-id: 5bafbcab-5090-47b5-ac8e-8c96ec1d6592 ClientRequestId: 5bafbcab-5090-47b5-ac8e-8c96ec1d6592
为了解决上面的问题,我将 todoTask 主体的 odatatype 设置为 null,但现在我遇到了以下无法解决的异常:
Code: generalException Message: Internal Server Error Inner error: AdditionalData: date: 2020-11-25T09:48:23 request-id: f5d52f43-c0b4-425e-83ec-652fadb7abf9 client-request-id: f5d52f43-c0b4-425e-83ec-652fadb7abf9 ClientRequestId: f5d52f43-c0b4-425e-83ec-652fadb7abf9
对于我们的应用程序,我们需要创建任务并同步到 outlook,因为这将投入生产,我们不能使用测试版。谁能帮我保存任务。
更新:
这是我如何设置 TodoTask 对象的代码:
var todoTask = new TodoTask();
todoTask.Title = "Subject";
todoTask.DueDateTime = new DateTimeTimeZone() { DateTime = dueDate.Date.ToString()};
todoTask.Status = TaskStatus.NotStarted;
todoTask.Importance = Importance.Normal;
todoTask.Body = new ItemBody
{
Content = "Test",
ContentType = BodyType.Text
};
todoTask.IsReminderOn = true;
todoTask.ReminderDateTime = new DateTimeTimeZone() {
DateTime = reminderTime.Value.ToString() };
todoTask.Extensions = new TodoTaskExtensionsCollectionPage();
todoTask.Extensions.Add(new OpenTypeExtension{
ExtensionName = "TestProperty",
AdditionalData = new Dictionary<string,object>{{"MyProp","MyValue"}}});
设置odatatype为null后,还需要设置TimeZone
属性 for DueDateTime
and ReminderDateTime
.
例如:
var todoTask = new TodoTask();
todoTask.Title = "Subject2";
todoTask.ODataType = null;
DateTime dueDate = DateTime.UtcNow.Date;
DateTime reminderTime = DateTime.UtcNow.Date;
todoTask.DueDateTime = new DateTimeTimeZone() {
TimeZone = "UTC",
ODataType = null,
DateTime = dueDate.Date.ToString()
};
todoTask.Status = TaskStatus.NotStarted;
todoTask.Importance = Importance.Normal;
todoTask.Body = new ItemBody
{
ODataType = null,
Content = "Test",
ContentType = BodyType.Text
};
todoTask.IsReminderOn = true;
todoTask.ReminderDateTime = new DateTimeTimeZone()
{
TimeZone = "UTC",
ODataType = null,
DateTime = reminderTime.Date.ToString()
};
todoTask.Extensions = new TodoTaskExtensionsCollectionPage();
todoTask.Extensions.Add(new OpenTypeExtension
{
ExtensionName = "TestProperty",
AdditionalData = new Dictionary<string, object> { { "MyProp", "MyValue" } }
});