我想将多个事件添加到日历中。今天,我遍历了长长的Event对象列表,一次在日历中添加了一项。如果有一种方法可以在一个请求中添加整个列表,那会很好吗?
foreach(var newEvent in myEventList)
{
await graphClient.Me.Calendars[id].Events
.Request()
.AddAsync(newEvent);
}
您可以使用批处理来执行此操作。 https://docs.microsoft.com/en-us/graph/json-batching。
使用直接REST,您可以使用
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/me/drive/root:/{file}:/content"
},
{
"id": "2",
"method": "GET",
"url": "/me/planner/tasks"
},
{
"id": "3",
"method": "GET",
"url": "/groups/{id}/events"
},
{
"id": "4",
"url": "/me",
"method": "PATCH",
"body": {
"city" : "Redmond"
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
SDK现在也使用BatchRequestContent和AddBatchRequestStep功能非常轻松地支持此功能。
我在11月的28分钟大关在Ignite展示了这一点。https://myignite.techcommunity.microsoft.com/sessions/82963?source=sessions