[英]Incomplete Microsoft.Graph.User profile data
When retrieving data via the Microsoft Graph User.Read
scope, I am only seeing data for the businessPhones
, displayName
, givenName
, id
, jobTitle
, mail
, mobilePhone
, officeLocation
, preferredLanguage
, surname
and userPrincipalName
properties. 通过微软的图形检索数据时User.Read
范围,我只看到了数据businessPhones
, displayName
, givenName
, id
, jobTitle
, mail
, mobilePhone
, officeLocation
, preferredLanguage
, surname
和userPrincipalName
属性。 I need to be able to expose data for the entire collection of properties, including items such as companyName
, state
, streetAddress
, etc. 我需要能够公开整个属性集合的数据,包括诸如companyName
, state
, streetAddress
等项目。
I have downloaded two samples from GitHub both of which ran as expected but neither provides the complete set of attributes from the Microsoft.Graph.User object. 我从GitHub下载了两个示例,两个示例均按预期运行,但都没有提供Microsoft.Graph.User对象的完整属性集。 I saw the complete set of User properties exposed in an ASP.Net Core demo, so, I know it can be done. 我在ASP.Net Core演示中看到了完整的User属性集,因此,我知道可以做到。 However, I'm not ready for ASP.Net Core just yet. 但是,我还没有准备好使用ASP.Net Core。
@model Microsoft.Graph.User
@{
ViewBag.Current = "Profile";
}
<h1>Profile</h1>
<table class="table">
@{
var properties = Model.GetType().GetProperties();
foreach (var child in properties)
{
object value = child.GetValue(Model);
string stringRepresentation;
if (!(value is string) && value is IEnumerable<string>)
{
stringRepresentation =
"["
+ string.Join(", ", (value as IEnumerable<string>).OfType<object>().Select(c => c.ToString()))
+ "]";
}
else
{
stringRepresentation = value?.ToString();
}
<tr>
<td> @child.Name </td>
<td> @stringRepresentation </td>
</tr>
}
}
</table>
As noted, the code iterates the User object properties as expected but only provides a subset of available results. 如前所述,该代码按预期迭代User对象的属性,但仅提供可用结果的子集。 I was able to validate my suspicions by retrieving my user profile data from the Microsoft Graph Explorer site and comparing it with the results from my app. 通过从Microsoft Graph Explorer网站检索用户配置文件数据并将其与我的应用程序的结果进行比较,我能够证实自己的怀疑。 The Graph Explorer provided data not available through my app. Graph Explorer提供了无法通过我的应用程序获得的数据。
What am I missing? 我想念什么? Any assistance is greatly appreciated. 非常感谢您的协助。
When requesting a User
resource without a $select
query parameter, Graph will insert a default $select
automatically: 当请求不带$select
查询参数的User
资源时,Graph将自动插入默认的$select
:
$select=businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName,id"
If you don't want the default set of properties, you need to construct your own $select
parameter: 如果您不想要默认的属性集,则需要构造自己的$select
参数:
$select=id,displayName,companyName
From the documentation : 从文档中 :
Note: Getting a user returns a default set of properties only ( businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName ). 注意:获取用户仅返回默认属性集( businessPhones,displayName,givenName,id,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName )。 Use
$select
to get the other properties and relationships for the user object. 使用$select
获取用户对象的其他属性和关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.