我正在尝试使用图api更新office 365组上的敏感度标签,如here所示,但我总是收到错误。
我指的是这个链接(https://docs.microsoft.com/en-us/microsoft-365/compliance/sensitivity-labels-teams-groups-sites?view=o365-worldwide),我最近看到微软发布了这个敏感标签功能的公开预览,可以应用于小组或团队。在我的租户中,已启用敏感度功能。

下面是我用来更新标签的代码。我使用的是nuget提供的最新版本的Microsoft.Graph包。
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();我收到的错误是

和完整的堆栈跟踪

有人能解释一下我在这里错过了什么吗?
发布于 2020-07-10 14:20:10
我很难分辨出这是一个NullReferenceException。
我已经在Microsoft Graph Explorer和代码中对其进行了测试,从我的角度来看,它们都工作得很好。
因此,为了进行故障排除,您可以在Microsoft Graph Explorer中测试它。如果出现同样的问题,则说明您所在地区的Microsoft Graph服务存在问题。只需等待修复即可。
如果它在Graph explorer中运行良好,但仍然不能在代码中运行,您可以从Graph explorer获取代码片段,并在您的代码中对其进行测试。

顺便说一下,这是我的代码供您参考(为了方便起见,我使用用户名/密码提供程序)。
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();https://stackoverflow.com/questions/62819340
复制相似问题