繁体   English   中英

在 Python 中使用 Azure 图形 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 \' '}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM