gpt4 book ai didi

c# - 如何使用 Microsoft Graph 客户端添加扩展?

转载 作者:行者123 更新时间:2023-12-03 20:29:29 25 4
gpt4 key购买 nike

我想使用 GraphClient 向用户添加扩展。我在任何地方都找不到合适的 C# 代码。任何人都可以帮忙吗?

Dictionary<string, object> addData = new Dictionary<string, object> {
{
"HoloFlag",
currentUser.UserPrincipalName
}
};

var extPatchObject = new OpenTypeExtension();

extPatchObject.ExtensionName = "com.holobeam3.extension";
extPatchObject.AdditionalData = addData;

try {
var extension = await _graphClient
.Me
.Extensions
.Request()
.AddAsync(extPatchObject);
Debug.Log(extension);
} catch (Exception ex) {
Debug.Log(ex.Message);
}

这是我到目前为止所尝试的。这将返回“访问被拒绝”异常,但访问现有扩展或其他没有问题 Me用户的端点。

最佳答案

要添加新扩展,请遵循以下代码:

 _graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async requestMessage =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
}));
Dictionary<string, object> addData = new Dictionary<string, object>
{
{"Key","Value" }
};
var extObject = new OpenTypeExtension();
extObject.ExtensionName = "TestExtension";
extObject.AdditionalData = addData;
try
{
await _graphClient.Users["usernamegoeshere"].Extensions.Request().AddAsync(extObject);
}

为了获取扩展,请遵循以下代码:
var userExtensions = await _graphClient.Me.Extensions["nameofExtension"].Request().GetAsync();

关于c# - 如何使用 Microsoft Graph 客户端添加扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52697187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com