通过 api 获取 Office 365 帐户的用户列表

Get users list of Office 365 account through api

我已经设置了 Office 365 企业版 account.How 我可以通过 API 访问我在帐户中添加的用户列表吗?

这是我需要获取的帐户和用户列表的屏幕截图- https://www.screencast.com/t/Bq1M3qegUQt

实际上我需要获取此用户列表以及每个用户的角色(全局管理员、用户(无管理员访问权限))。

Office 365 API 功能也可通过 Microsoft Graph(推荐)获得,这是一个统一的 API,其中包括来自其他 Microsoft 服务的 API。

使用 Microsoft Graph api ,您可以 list users 通过:

GET https://graph.microsoft.com/v1.0/users

您可以使用 List memberOf 获取用户是其直接成员的组和目录角色:

GET /users/{id | userPrincipalName}/memberOf

以下结果供您参考:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
    "value": [
        {
            "@odata.type": "#microsoft.graph.directoryRole",
            "id": "bee946b1-bf9c-4d97-bdb6-41931e37e677",
            "deletedDateTime": null,
            "description": "Company Administrator role has full access to perform any operation in the company scope.",
            "displayName": "Company Administrator",
            "roleTemplateId": "62e90394-69f5-4237-9190-012177145e10"
        },
        {
            "@odata.type": "#microsoft.graph.group",
            "id": "e1b32e43-dab2-49e1-a2f3-51e391888a44",
            "deletedDateTime": null,
            "classification": null,
            "createdDateTime": "2017-04-06T08:15:54Z",
            "description": "MySite",
            "displayName": "MySite",
            "groupTypes": [
                "Unified"
            ],
            "mail": "MySite@chencl.onmicrosoft.com",
            "mailEnabled": true,
            "mailNickname": "MySite",
            "onPremisesLastSyncDateTime": null,
            "onPremisesProvisioningErrors": [],
            "onPremisesSecurityIdentifier": null,
            "onPremisesSyncEnabled": null,
            "proxyAddresses": [
                "SMTP:MySite@chencl.onmicrosoft.com"
            ],
            "renewedDateTime": "2017-04-06T08:15:54Z",
            "securityEnabled": false,
            "visibility": "Public"
        }
    ]
}

您可以获得 the roles by filtering the results which @odata.type is #microsoft.graph.directoryRole . You could check the administrator roles here . If user has no admin access(User) , there is no directoryRole values with above rest api . For how to get access tokens to call Microsoft Graph , you could click here 了解更多详情。