如何使用Microsoft Graph创建和获取Outlook事件打开扩展数据.NET SDK



虽然MSDN有一些关于如何创建和获取开放扩展的好文档,但我在使用Microsoft Graph SDK时找不到任何相同目的的文档。

所以我一直在尝试以下方法。

使用新的打开类型扩展更新事件:

await new EventRequest(fullEventUrl graphClient, null)
.UpdateAsync(new Event
{
// Change the subject so that I can tell the event is updated by looking at my calendar
Subject = "Updated Event " + Guid.NewGuid(),
// Add a new open type extension.
Extensions = new EventExtensionsCollectionPage
{
// I also don't know how to add my own properties to the extension.
// Tried using my own derived class here but didn't work either.
new OpenTypeExtension {ExtensionName = "com.consoto.customExtensionName"}
}
});

这个调用为我提供了一个带有事件详细信息的成功响应,但是,返回的事件JSON中没有扩展。这似乎表明创建该事件时忽略了我在其中添加的扩展。

使用扩展扩展筛选器获取事件:

await new EventRequest(fullEventUrl, graphClient, null).Expand(
"Extensions($filter=id eq 'com.consoto.customExtensionName')").GetAsync();

这成功地获取了事件,JSON中有一个空的扩展集合。

是我遗漏了什么,还是SDK在4年后仍未更新以支持创建开放扩展?

我从这个堆栈溢出问题中找到了答案:修补Microsoft。图形事件不会添加新的扩展。

长话短说,我想做的是;补丁";,以更新现有事件。

我无法在修补程序中添加扩展,因为该扩展与我正在修补的事件是不同的实体。

扩展必须按照问题的建议单独添加,使用SDK有多种方法可以做到这一点:

var extension = new OpenTypeExtension {ExtensionName = "MyExtensionName"};
// Method 1 if you don't have the event URL:
graphClient.Users[user].Events[eventId].Extensions.Request().AddAsync(extension);
// Method 2 if you have the event URL:
var extensionCollectionUrl = "https://graph.microsoft.com/v1.0/Users/24c.../Events/AQM.../Extensions";
new OpenTypeExtensionRequest(extensionCollectionUrl, graphClient, null).CreateAsync(extension);
// Method 2 other alternatives:
new EventExtensionsCollectionRequest(extensionCollectionUrl, graphClient, null).AddAsync(extension);
new EventExtensionsCollectionRequestBuilder(extensionsUrl, graphClient).Request().AddAsync(extension);
new OpenTypeExtensionRequestBuilder(extensionsUrl, graphClient).Request().CreateAsync(extension);

至于如何添加除";ExtensionName";,您可以将它们添加为";AdditionalData":

var extension = new OpenTypeExtension
{
ExtensionName = extensionName,
AdditionalData = new Dictionary<string, object>
{
{"testKey", "testValue"}
}
};

但是,不支持在附加数据上筛选事件(或任何其他类型的资源(,因此只有当附加数据不用于查找相应的事件时,这才有用。

最新更新