Python 如何在AZURE广告中获得部门价值
我正在尝试检索Azure Active Directory中的部门值Python 如何在AZURE广告中获得部门价值,python,azure,Python,Azure,我正在尝试检索Azure Active Directory中的部门值 部门的正确电话是什么? 这是我的index.html <h1 style="margin-top: 50px;">Welcome {{ user.name }}!</h1> <h1 style="margin-top: 50px;">Your Department: {{ user.department }}</h1> 您可
部门的正确电话是什么?
这是我的index.html
<h1 style="margin-top: 50px;">Welcome {{ user.name }}!</h1>
<h1 style="margin-top: 50px;">Your Department: {{ user.department }}</h1>
您可以使用图形api:https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}
获取用户信息
在api的响应中,默认情况下不存在字段department
。您可以将?$select=department
附加到图形api中,如:https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}?$select=department
。然后,您可以在api的响应中获得部门
字段
顺便说一下,如果您使用
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}?$select=department
,它将只响应一个字段department
。如果还需要类似于name
的字段,则需要使用https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}?$select=displayName,department
你好,我已经编辑了代码above@EltonTan那你有什么问题?graph api是否响应部门
字段?它仍然没有显示给我。@EltonTan您似乎没有在代码中添加部门
,$select
?哦,等等,我已经添加了,但它没有显示
graph_url = 'https://graph.microsoft.com/v1.0'
# get accessToken
def get_user(token):
# Send GET to /me
user = requests.get(
'{0}/me'.format(graph_url),
headers={
'Authorization': 'Bearer {0}'.format(token)
},
params={
'$select': 'displayName,mail,mailboxSettings,userPrincipalName,department'
})
# Return the JSON result
return user.json()