如何使用 Microsoft Graph 客户端添加扩展?
How to add extensions using Microsoft Graph Client?
我想使用 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);
}
到目前为止,这是我尝试过的。这 returns 是一个 "access denied" 异常,但在访问用户的现有扩展或其他 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();
GraphServiceClient client = AuthHelper.GetAuthClient();
var currentUser = await client.Me.Request().GetAsync();
string id = currentUser.Id;
var test = await client.Me.Extensions.Request().GetAsync();
Console.WriteLine(currentUser.DisplayName);
Console.WriteLine("Click to update extension");
Console.ReadLine();
Dictionary<string, object> addData = new Dictionary<string, object>()
{
{"Key", "Value"}
};
var extObject = new OpenTypeExtension()
{
ExtensionName = "testExtension",
AdditionalData = addData
};
try
{
await client.Me.Extensions.Request().AddAsync(extObject);
}
catch (Exception ex)
{
//
}
我想使用 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);
}
到目前为止,这是我尝试过的。这 returns 是一个 "access denied" 异常,但在访问用户的现有扩展或其他 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();
GraphServiceClient client = AuthHelper.GetAuthClient();
var currentUser = await client.Me.Request().GetAsync();
string id = currentUser.Id;
var test = await client.Me.Extensions.Request().GetAsync();
Console.WriteLine(currentUser.DisplayName);
Console.WriteLine("Click to update extension");
Console.ReadLine();
Dictionary<string, object> addData = new Dictionary<string, object>()
{
{"Key", "Value"}
};
var extObject = new OpenTypeExtension()
{
ExtensionName = "testExtension",
AdditionalData = addData
};
try
{
await client.Me.Extensions.Request().AddAsync(extObject);
}
catch (Exception ex)
{
//
}