问题:如何在 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:pakistanq参数的_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键。

文字空间也可以工作,但是您必须将其转义或将参数括在引号中。

Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐