Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在AZURE广告中获得部门价值_Python_Azure - Fatal编程技术网

Python 如何在AZURE广告中获得部门价值

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> 您可

我正在尝试检索Azure Active Directory中的部门值

部门的正确电话是什么?
这是我的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()