简体   繁体   English

Microsoft Graph API:查询不起作用

[英]Microsoft Graph API: query not working

I've been trying to use the following query with the Microsoft graph API:我一直在尝试将以下查询与 Microsoft 图形 API 一起使用:

"groups?$filter=startswith(displayName, '" + term + "')"

So this term 's value is taken from an input html:所以这个term的值取自输入的html:

在此处输入图片说明

and through python I'm inserting it to perform the search with the query:并通过 python 我插入它以使用查询执行搜索:

@APP.route('/search')
def search():
    params = request.args.to_dict()
    term = params.get('term')
    queryGroup = "groups?$filter=startswith(displayName, '" + term + "')"
    result = MSGRAPH.get(queryGroup, headers=request_headers()).data

    return flask.render_template('home-page.html', result=result)

When I try looking for an existent group in the Azure AD, as a result I get this:当我尝试在 Azure AD 中查找现有组时,结果是:

b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">\r\n<HTML><HEAD><TITLE>Bad Request</TITLE>\r\n<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>\r\n<BODY><h2>Bad Request</h2>\r\n<hr><p>HTTP Error 400. The request is badly formed.</p>\r\n</BODY></HTML>\r\n'

According to Microsoft's Documentation, I see that my query is well structured.根据 Microsoft 的文档,我发现我的查询结构良好。

I would like you guys to help me know, what may be failing here?我希望你们帮助我知道,这里可能会失败什么?

I'm using v1.0 of the API, and also tried it out with the same version in the graph explorer.(Where it worked out, which is odd for me)我正在使用 API 的 v1.0,并在图形资源管理器中使用相同版本进行了尝试。(在那里成功了,这对我来说很奇怪)

I've been thinking about using the $search parameter, but it does not work for this type of collection (Groups)我一直在考虑使用$search参数,但它不适用于这种类型的集合(组)

The full URI that I'm sending is :我发送的完整 URI 是:

https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,<here I put the searched value>)

Thanks!谢谢!

You can change your query string in your Python project first, to confirm if other query condition works well.您可以先在 Python 项目中更改查询字符串,以确认其他查询条件是否正常。

And if your project and graph explorer use different user credentials, you maybe need to check the permission again.如果您的项目和图形浏览器使用不同的用户凭据,您可能需要再次检查权限。

All in all, try different query first.总而言之,首先尝试不同的查询。

400 means bad request. 400 表示错误请求。 It could be because of url encoding.这可能是因为 url 编码。 Url encode the query string. Url 编码查询字符串。

Something like就像是

String query = "Extensions($filter=Id eq 'c.i.m.p.server.entities.outlook.Event'";
String url = "https://graph.microsoft.com/v1.0/users/{userId}/calendars/{calendarId}/events?
               $expand=" + URLEncoder.encode(query, StandardCharsets.UTF_8.name());

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

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