在 Python 中使用 Azure Graph API 使用基于过滤器的查询参数
Using Filter based query parameters using Azure Graph API in Python
我正在使用 MSAL Graph API 从 Azure AD 检索数据。因为我想要特定信息,所以我尝试使用可以作为参数传递的 $filter。但是由于 $filter 接受 AND/OR 子句,我试图通过传递多个值来获取信息,例如
app = ConfidentialClientApplication(client_id = patclientid,
authority="https://login.microsoftonline.com/tenantID",
client_credential = patclient_credential)
parameters = {'$filter':'createdDateTime ge 2020-06-18 and appDisplayName eq appName'}
if "access_token" in result:
print(result['access_token'])
user_data = requests.get( # Use token to call downstream service
"https://graph.microsoft.com/beta/auditLogs/signIns",
headers={'Authorization': 'Bearer ' + result['access_token']},
params=parameters).json()
在上面的 运行 上它给了我以下错误
"code": "BadRequest",
"message": "Invalid filter clause",
我已经在 POSTMAN 中尝试了相同的请求并且它工作正常。但不知何故,它在 python.
中不起作用
问题是由于缺少"
('
)个字符导致的,只需使用:
parameters = {'$filter':'createdDateTime ge 2020-06-18 and appDisplayName eq \'OFSC \' '}
我正在使用 MSAL Graph API 从 Azure AD 检索数据。因为我想要特定信息,所以我尝试使用可以作为参数传递的 $filter。但是由于 $filter 接受 AND/OR 子句,我试图通过传递多个值来获取信息,例如
app = ConfidentialClientApplication(client_id = patclientid,
authority="https://login.microsoftonline.com/tenantID",
client_credential = patclient_credential)
parameters = {'$filter':'createdDateTime ge 2020-06-18 and appDisplayName eq appName'}
if "access_token" in result:
print(result['access_token'])
user_data = requests.get( # Use token to call downstream service
"https://graph.microsoft.com/beta/auditLogs/signIns",
headers={'Authorization': 'Bearer ' + result['access_token']},
params=parameters).json()
在上面的 运行 上它给了我以下错误
"code": "BadRequest",
"message": "Invalid filter clause",
我已经在 POSTMAN 中尝试了相同的请求并且它工作正常。但不知何故,它在 python.
中不起作用问题是由于缺少"
('
)个字符导致的,只需使用:
parameters = {'$filter':'createdDateTime ge 2020-06-18 and appDisplayName eq \'OFSC \' '}