大佬教程收集整理的这篇文章主要介绍了使用分页在 Python 中返回所有 Azure AD 用户信息,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Python 脚本中获取 Azure AD 数据。我特别感兴趣的是来自 Azure 中 name
站点的 email
、jobtitle
和 Users
。
但是,get 请求限制为 100 行,我认为这与分页有关。此外,jobtitle
为空,这与应用注册有关。
问题
我的代码是:
import logging
import Json
import msal
import requests
import pandas
# Globals
token = None
graphAPIVersion = "v1.0"
uri = "https://graph.microsoft.com/{v}/{r}"
headers = None
# Functions
def authenticate():
global token
global headers
authority = "https://login.microsoftonline.com/<tenant ID>"
appID = "<app ID>"
appSecret = "<app secret>"
scope = ["https://graph.microsoft.com/.default"]
app = msal.ConfIDentialClIEntApplication(
appID,authority=authority,clIEnt_credential = appSecret)
token = app.acquire_token_silent(scope,account=NonE)
if not token:
token = app.acquire_token_for_clIEnt(scopes=scopE)
headers = {'Authorization': 'Bearer ' + token['access_token']}
return
def users(Format=TruE):
return query(graphAPIVersion,"/users?$SELEct=displayname,givenname,jobtitle,email,department",Format)
def query(v,r,Format=TruE):
dest = uri.format(v=v,r=r)
result = requests.get(dest,headers=headers).Json()
if Format:
print(pandas.Json_normalize(result["value"]))
else:
return result["value"]
您可以只使用 None
参数来页面 Microsoft Graph 数据。如果您使用此参数,您将获得一个附加链接,名称为:$top
以获取下一页数据。详情见this official doc。
我还使用您的代码进行了快速测试,如下所示:
@odata.nextLink
它对我有用:
以上是大佬教程为你收集整理的使用分页在 Python 中返回所有 Azure AD 用户信息全部内容,希望文章能够帮你解决使用分页在 Python 中返回所有 Azure AD 用户信息所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。