c# - getByIds 的 Microsoft.Graph 方法未返回包含其所有属性的完整对象
问题描述
在我的项目中,我使用GetByIds
Microsoft.Graph API ( link ) 和 Select 字符串的方法,它工作正常并且返回了选择字符串中提到的所有属性。但是最近,它已经停止工作,并且没有返回包含选择字符串中提供的所有属性的完整对象。即使我不提供 Select 属性,也不会完全返回属性,尤其是我需要的属性,例如accountenabled
, businessphones
, city
, companyname
, country
, department
,jobtitle
. 这种方法对我的项目非常重要,微软在他们的后端 Microsoft.Graph API 中对它进行了故障处理。拜托,有人可以帮我找到这种方法的替代方法,该方法采用用户 ID 列表并返回其所有属性吗?Microsoft 是否有任何 ETA 可以使用此“GetByIds”方法解决此问题?
我的代码如下:
var directoryObjects = new List<Microsoft.Graph.DirectoryObject>();
var types = new List<String>()
{
"user"
};
string select ="displayname,mail,mailnickname,onpremisessecurityidentifier,onpremisessyncenabled,proxyaddresses,id,odatatype,accountenabled,businessphones,city,companyname,country,department,givenname,imaddresses,jobtitle,mobilephone,onpremisesimmutableid,passwordpolicies,officelocation,postalcode,preferredlanguage,state,streetaddress,surname,usagelocation,userprincipalname,usertype";
var responseWithSelect = _graphServiceClient.DirectoryObjects.GetByIds(identitiesList,types).Request().Select(select).PostAsync().Result;
var responseWithoutSelect = _graphServiceClient.DirectoryObjects.GetByIds(identitiesList,types).Request().PostAsync().Result;
解决方案
正如已知问题所示:
使用从 ID 列表中获取目录对象请求对象应返回完整对象。但是,当前 v1.0 端点上的用户对象返回的属性集有限。作为临时解决方法,当您将该操作与 $select 查询选项结合使用时,将返回更完整的用户对象。此行为不符合 OData 规范。由于此行为将来可能会更新,因此仅当您为 $select= 提供您感兴趣的所有属性时使用此解决方法,并且仅当将来对此解决方法的重大更改是可接受的时才使用此解决方法。
我使用 Fiddler 来监控请求。我发现实际的请求是:
POST https://graph.microsoft.com/v1.0/directoryObjects/microsoft.graph.getByIds?$select=displayname,mail,mailnickname,onpremisessecurityidentifier,onpremisessyncenabled,proxyaddresses,id,odatatype,accountenabled,businessphones,city,companyname,country,department,givenname,imaddresses,jobtitle,mobilephone,onpremisesimmutableid,passwordpolicies,officelocation,postalcode,preferredlanguage,state,streetaddress,surname,usagelocation,userprincipalname,usertype HTTP/1.1
SdkVersion: Graph-dotnet-1.18.0
FeatureFlag: 0000004F
Cache-Control: no-store, no-cache
Authorization: Bearer eyJ0eXAiOiJKV1Qi*****************X5Q
Accept-Encoding: gzip
Content-Type: application/json
Host: graph.microsoft.com
Content-Length: 65
Expect: 100-continue
{"ids":["ab6d4cd6-fc2d-40c7-a676-f8773aebfb5f"],"types":["user"]}
但是,在响应中,并未返回所有必需的属性。甚至displayname
没有被退回。我进一步检查,发现实际的属性名称是displayName
. 因此,我将其更改为正确的,并且能够得到displayName
返回。
所以,
API 本身有一些已知问题会阻止它返回请求的值。
选择字符串现在区分大小写。
您可以相应地更改您的代码,看看它是否有帮助。
推荐阅读
- excel - 如何通过范围内的 ID 和日期过滤找到最大值和最小值
- core-data - Previewing ContentView with CoreData
- multithreading - 优化 OpenCL 缓冲区写入?
- pandas - 递归地列出树/有向图中节点的邻居,对于图中的所有节点,一次一个“级别”?
- here-api - Fleet Telematics Waypoints Sequence response time
- java - 在 Scala 中对 Java 列表进行平面映射
- android - 尝试 UnitTest 时,出现 Jacoco 错误。即使它没有使用
- google-cloud-platform - Terraform:自动进行身份验证以将 GCP 存储桶挂载到 VM
- c++ - 在初始化列表中强制转换 shared_ptr
- ios - 如何在 UITableView 中的分隔符附近添加按钮