Azure active directory 使用graph api将灵敏度标签更新到office365组
我正在尝试使用graph api更新office 365组上的敏感度标签,如图所示,但我始终收到错误消息 我指的是这个链接(),我最近看到微软发布了这个敏感标签功能的公开预览,它可以应用于团体或团队。在我的租户中,已启用灵敏度功能 下面是我用来更新标签的代码。我使用的是nuget提供的Microsoft.Graph的最新版本Azure active directory 使用graph api将灵敏度标签更新到office365组,azure-active-directory,microsoft-graph-api,office365,Azure Active Directory,Microsoft Graph Api,Office365,我正在尝试使用graph api更新office 365组上的敏感度标签,如图所示,但我始终收到错误消息 我指的是这个链接(),我最近看到微软发布了这个敏感标签功能的公开预览,它可以应用于团体或团队。在我的租户中,已启用灵敏度功能 下面是我用来更新标签的代码。我使用的是nuget提供的Microsoft.Graph的最新版本 MSGraph.GraphServiceClient graphClient = GetAuthenticatedClient(); string grpId =
MSGraph.GraphServiceClient graphClient = GetAuthenticatedClient();
string grpId = "<group id here>"; // irrelevant not shown here how group id is acquired
var groupToUpdate = new Group
{
AssignedLabels = new List<AssignedLabel>()
{
new AssignedLabel
{
LabelId = "480dd7e5-2378-47bc-a023-511ad6a967ce"
}
}
};
graphClient.Groups[grpId].Request().UpdateAsync(groupToUpdate).Wait();
MSGraph.GraphServiceClient graphClient=GetAuthenticatedClient();
字符串grpId=”“;//此处未显示如何获取组id
var groupToUpdate=新组
{
AssignedLabels=新列表
和完整的堆栈跟踪
有人能解释一下我在这里遗漏了什么吗?我很难说这是一个NullReferenceException
我已经在MicrosoftGraphExplorer和代码中对其进行了测试,从我的角度来看,这两个工具都工作得很好
因此,对于疑难解答,您可以在中进行测试。如果它出现相同的问题,则您所在地区的Microsoft Graph service可能有问题。请等待修复
如果它在Graph explorer中运行良好,但在代码中仍然不起作用,则可以从Graph explorer中获取代码片段并在代码中进行测试
顺便说一句,这是我的代码供您参考(为了方便起见,我使用用户名/密码提供程序)
IPPublicClient应用程序publicClientApplication=PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.Build();
字符串[]范围=新字符串[]{”https://graph.microsoft.com/.default" };
UsernamePasswordProvider authProvider=新的UsernamePasswordProvider(publicClientApplication,作用域);
GraphServiceClient graphClient=新的GraphServiceClient(authProvider);
var str=“{my password here}”;
var password=new SecureString();
foreach(str中的字符c)密码;
User me=wait graphClient.me.Request()
.WithUserName密码(“{my user name here}”,密码)
.GetAsync();
var组=新组
{
AssignedLabels=新列表()
{
新指定标签
{
LabelId=“38feb82c-de40-4a15-b706-5faa1202e103”
}
}
};
字符串grpId=“45e095a6-5c43-4832-b82c-6aa586176d31”;
graphClient.Groups[grpId].Request().UpdateAsync(group.Wait();
我很难说这是一个NullReferenceException
我已经在MicrosoftGraphExplorer和代码中对其进行了测试,从我的角度来看,这两个工具都工作得很好
因此,对于疑难解答,您可以在中进行测试。如果它出现相同的问题,则您所在地区的Microsoft Graph service可能有问题。请等待修复
如果它在Graph explorer中运行良好,但在代码中仍然不起作用,则可以从Graph explorer中获取代码片段并在代码中进行测试
顺便说一句,这是我的代码供您参考(为了方便起见,我使用用户名/密码提供程序)
IPPublicClient应用程序publicClientApplication=PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.Build();
字符串[]范围=新字符串[]{”https://graph.microsoft.com/.default" };
UsernamePasswordProvider authProvider=新的UsernamePasswordProvider(publicClientApplication,作用域);
GraphServiceClient graphClient=新的GraphServiceClient(authProvider);
var str=“{my password here}”;
var password=new SecureString();
foreach(str中的字符c)密码;
User me=wait graphClient.me.Request()
.WithUserName密码(“{my user name here}”,密码)
.GetAsync();
var组=新组
{
AssignedLabels=新列表()
{
新指定标签
{
LabelId=“38feb82c-de40-4a15-b706-5faa1202e103”
}
}
};
字符串grpId=“45e095a6-5c43-4832-b82c-6aa586176d31”;
graphClient.Groups[grpId].Request().UpdateAsync(group.Wait();
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.Build();
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var str = "{my password here}";
var password = new SecureString();
foreach (char c in str) password.AppendChar(c);
User me = await graphClient.Me.Request()
.WithUsernamePassword("{my user name here}", password)
.GetAsync();
var group = new Group
{
AssignedLabels = new List<AssignedLabel>()
{
new AssignedLabel
{
LabelId = "38feb82c-de40-4a15-b706-5faa1202e103"
}
}
};
string grpId = "45e095a6-5c43-4832-b82c-6aa586176d31";
graphClient.Groups[grpId].Request().UpdateAsync(group).Wait();