如何通过Microsoft Graph API或.NET获取用户关联的敏感度标签?
解决Microsoft Graph API获取敏感度标签的问题
一、API请求400错误的解决
你使用的users/{id}/security/informationProtection/sensitivityLabels不是有效的Microsoft Graph端点,这直接导致了Unexpected segment DynamicPathSegment错误。根据需求,正确的调用方式分两种场景:
- 获取租户内所有可用的敏感度标签
敏感度标签属于租户级资源,需从根security节点发起请求:
GET https://graph.microsoft.com/v1.0/security/informationProtection/sensitivityLabels
- 获取特定用户的默认敏感度标签
如果要获取用户设置的默认标签,使用以下端点:
GET https://graph.microsoft.com/v1.0/users/{id}/settings/informationProtection/defaultSensitivityLabel
二、C# SDK代码错误的解决
UserItemRequestBuilder不存在Security属性,因为Security是Graph客户端的根节点导航属性,并非用户节点的子属性。正确代码如下:
- 获取租户所有敏感度标签
var result = await graphClient.Security.InformationProtection.SensitivityLabels.GetAsync();
- 获取特定用户的默认敏感度标签
var defaultLabel = await graphClient.Users["{id}"].Settings.InformationProtection.DefaultSensitivityLabel.GetAsync();
三、所需权限
调用上述端点需配置对应的权限:
- 获取租户标签:
InformationProtectionPolicy.Read.All - 获取用户默认标签:
User.Read.All(应用权限)或User.Read(委派权限)
内容的提问来源于stack exchange,提问作者Carol Bradley
相关产品推荐
相关产品推荐

