如何在 Github API 的搜索查询中有一个“或”?
·
问题:如何在 Github API 的搜索查询中有一个“或”?
Github API 允许我们通过不同的参数搜索用户,其中一个参数是location。运行以下查询将为居住在巴基斯坦的所有用户提供:
curl https://api.github.com/search/users?q=location:pakistan
现在,我想获取所有居住在巴基斯坦或印度的用户,但似乎 Github 并没有定义在巴基斯坦和印度之间建立或连接的方式。
我尝试了以下查询,但这些都不起作用:
curl https://api.github.com/search/users?q=location:pakistan&location:india
curl https://api.github.com/search/users?q=location:(pakistan|india)
解答
您的第一次尝试很接近,但不起作用,因为location不是它自己的 HTTP GET 参数。整个字符串location:pakistan是q参数的_value_。
当您执行?q=location:pakistan&location:india时,您实际上是在提交类似
-
q的值为location:pakistan -
location:india是键,但没有值
相反,使用+或%20连接多个location键:
curl https://api.github.com/search/users?q=location:pakistan+location:india
现在整个location:pakistan+location:india字符串作为值传递给q键。
文字空间也可以工作,但是您必须将其转义或将参数括在引号中。
更多推荐


所有评论(0)