我已经获取到了listid和taskid,以及task里面的内容,我需要设置task是否已经完成,我尝试通过设置completedDateTime来实现
但是无论completedDateTime设置为何值时都不能生效
这是我的代码,需要修改哪里才能正常工作?
public static async Task<bool> EditTaskItem(string bear, string listId, string task, string? text, bool? isCheck, DateTime? time, string? body)
{
var obj = new JObject();
if (text != null)
{
obj.Add("title", text);
}
if (isCheck is { } check)
{
if (check)
{
obj.Add("completedDateTime", new JObject()
{
{ "timeZone", "UTC" },
{ "dateTime", BuildTime(DateTime.UtcNow) }
});
}
else
{
obj.Add("completedDateTime", null);
}
}
if (time is { } time1)
{
obj.Add("dueDateTime", new JObject()
{
{ "timeZone", "UTC" },
{ "dateTime", BuildTime(time1.ToUniversalTime()) }
});
}
if (body != null)
{
obj.Add("body", new JObject()
{
{ "contentType", "text" },
{ "content", body }
});
}
var content = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
var req = new HttpRequestMessage()
{
RequestUri = new Uri($"https://graph.microsoft.com/v1.0/me/todo/lists/{listId}/tasks/{task}"),
Method = HttpMethod.Patch,
Content = content
};
req.Headers.Add("Authorization", "Bearer " + bear);
try
{
var res = await OAuth.Client.SendAsync(req);
return res.StatusCode == HttpStatusCode.OK;
}
catch (Exception e)
{
Logs.Error("todo error", e);
return false;
}
}