简体   繁体   English

Microsoft Graph API:获取用户组织

[英]Microsoft Graph API: get user organization

I am using Microsoft Graph API to get some details of the user.我正在使用 Microsoft Graph API 来获取用户的一些详细信息。 I also use AD for Authentication and Authorization.我还使用 AD 进行身份验证和授权。

In this application, user, after login, will search for some user(s) and needs some details for all the users matching the search.在此应用程序中,用户在登录后将搜索一些用户,并需要所有与搜索匹配的用户的详细信息。

I hit below users api , with filters, but I am not getting any details regarding company name for matching user(s).我使用过滤器点击了users api ,但我没有得到有关匹配用户的公司名称的任何详细信息。

https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'jo')

Below is the response for the same下面是同样的回复

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
  "@odata.nextLink": "https://graph.microsoft.com/v1.0/users?$skiptoken=X%2744537074020001000000203A636F6D7061735F766A61407465737473636F7270696F67726F75702E6E657429557365725F33386664353661362D366361612D343939332D393264642D383439633938613039393033B900000000000000000000%27",
  "value": [
        {
            "businessPhones": [],
            "displayName": "John Doe",
            "givenName": "John",
            "jobTitle": null,
            "mail": null,
            "mobilePhone": null,
            "officeLocation": null,
            "preferredLanguage": null,
            "surname": "Doe",
            "userPrincipalName": "jdoe@mycomp.net",
            "id": "c8f63ba1-5150-44c1-b456-468040f12345"
        }
  ]
}

What I need to do to get the company name for the users of my organization?我需要做什么才能为我的组织的用户获取公司名称?

The user resource returns only a subset of properties by default.默认情况下, user资源仅返回属性的子集。 Per 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获取用户对象的其他属性和关系。

In other words, you need to add a $select parameter to your query that lists the properties you want to be returned.换句话说,您需要将$select参数添加到您的查询中,以列出您想要返回的属性。 For example, if you want to retrieve id , userPrincipalName , and companyName , you would use:例如,如果您想检索iduserPrincipalNamecompanyName ,您可以使用:

https://graph.microsoft.com/v1.0/users?$select=displayName,id,jobTitle,companyName

The complete set of available properties can be found in the User Resource Type docs.完整的可用属性集可以在用户资源类型文档中找到。

I want this details for all the users from just one login我想通过一次登录获得所有用户的详细信息

This is not possible.这不可能。 The only way to get organization details is using https://graph.microsoft.com/v1.0/organization api. 获取组织详细信息的唯一方法是使用https://graph.microsoft.com/v1.0/organization api。

You need to provide the access token to call this api.您需要提供访问令牌才能调用此 api。 In your application, you login with one user to get the access token.在您的应用程序中,您使用一位用户登录以获取访问令牌。

If you use common in the token request url, you will get the default organization for that login user.如果您在令牌请求 url 中使用 common,您将获得该登录用户的默认组织。

If you use specific tenant in the request url, you will get the organization details for that tenant.如果您在请求 url 中使用特定租户,您将获得该租户的组织详细信息。

If you just want to get the companyName of the user, you can call https://graph.microsoft.com/beta/users/{userid} to get it.如果只想获取用户的companyName,可以调用https://graph.microsoft.com/beta/users/{userid}获取。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM