我已经设置了Office 365商业帐户。如何通过API访问我在帐户中添加的用户列表?
以下是我需要提取的帐户和用户列表的屏幕截图 - https://www.screencast.com/t/Bq1M3qegUQt。
实际上我需要获得此用户列表以及每个用户的角色(全局管理员,用户(无管理员访问权限))。
答案 0 :(得分:1)
Office 365 API功能也可通过Microsoft Graph(推荐)获得,这是一个统一的API,其中包含来自其他Microsoft服务的API。
使用Microsoft Graph api,您可以{/ 3}}通过:
GET https://graph.microsoft.com/v1.0/users
您可以使用list users来获取用户所属的组和目录角色:
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"
}
]
}
您可以通过过滤@odata.type
为#microsoft.graph.directoryRole
的结果来获得List memberOf。您可以检查管理员角色the roles。如果用户没有管理员权限(用户),则没有directoryRole
值以及其余的api。有关如何访问令牌以调用Microsoft Graph,您可以单击here以获取更多详细信息。