为什么 Microsoft Graph 需要 $select 和 $expand=extensions? [英] why does Microsoft Graph require $select with $expand=extensions?

查看:46
本文介绍了为什么 Microsoft Graph 需要 $select 和 $expand=extensions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Graph Explorer 中,当我进行身份验证并使用获取开放扩展"示例时,它会针对此端点执行 GET:

In the Graph Explorer, when I authenticate and use the "get an open extension" sample, it does a GET against this endpoint:

https://graph.microsoft.com/v1.0/me?$select=id,displayName,mail,mobilePhone&$expand=extensions

这将返回我在创建开放扩展"示例中添加的任何扩展.但是如果我删除 $select 参数,使端点看起来像这样......

That returns any extensions I've added with the "create an open extension" sample. But if I remove the $select parameter so that the endpoint looks like this ...

https://graph.microsoft.com/v1.0/me?$expand=extensions

...然后我收到一条错误消息,指出'microsoft.graph.user'类型的实体实例值没有属性'id'的值."看来我需要一个$select参数来返回扩展的扩展.而且 $select 值是什么并不重要 - 我可以使用一个与 JSON 有效负载中的任何字段都不对应的无意义字符串,并且它工作正常.

... then I get an error stating that ""The entity instance value of type 'microsoft.graph.user' doesn't have a value for property 'id'." It seems I need to have a $select parameter to return the expanded extensions. And it doesn't matter what the $select value is - I can use a nonsensical string that doesn't correspond to any fields in the JSON payload, and it works fine.

为什么在这种情况下需要 $select 参数?

Why is a $select parameter required in this case?

推荐答案

除了 $select=fieldnotfound 之外,我可以复制这个.无论是否使用该 $select 语句,我都会返回相同的错误.我无法解释为什么你会看到这种行为,但我可以提供一些关于这里出了什么问题的见解.

I'm able to replicate this with exception of $select=fieldnotfound. I get the same error returned with or without that $select statement. I can't explain why this you're seeing that behavior but I can provide some insight into what is going wrong here.

首先介绍一下幕后发生的事情.

First a little background on what is happening under the covers.

当您在没有附加参数的情况下调用 /me 时,会自动使用默认的 $select 参数.默认情况下,它使用以下内容:

When you call /me with no additional params, a default $select parameter is used automatically. By default it uses the following:

$select=businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName,id

如您所见,id 实际上是所选字段之一.理论上,简单地添加 $expand=extentions 应该可以按预期工作.不幸的是,添加 $expand 似乎也稍微改变了底层 $select 语句中的字段.即,它删除 id 字段:

As you can see, id is in fact one of the selected fields. In theory, simply adding $expand=extentions should therefore work as expected. Unfortunately it seems that adding $expand also slightly changes the fields in underlying $select statement as well. Namely, it drops the id field:

$select=businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName

如果我同时使用两者,它会按预期工作:

If I use specify both however, it works as expected:

https://graph.microsoft.com/v1.0/me?$select=businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName,id&$expand=扩展

我怀疑这是关于默认字段选择的错误,但我会向 Graph 团队提出这个问题.上面的查询至少应该允许您在此期间继续前进.

I suspect this is a bug around the default field select but I'll defer to the Graph team on that. The above query should at least allow you to move forward in the meantime.

这篇关于为什么 Microsoft Graph 需要 $select 和 $expand=extensions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆