如何从GitHub检索受欢迎的用户?

时间:2019-08-08 08:56:28

标签: javascript github github-api

我正在尝试获取GitHub上的常用存储库和用户列表。

他们的API has an example查找必须在q查询参数下发送给定条件的用户,这是必需参数,但是我不确定如何将其发送为“空”

查询应列出用户并按关注者排序,我很接近,但是我不确定在q中发送什么内容

`https://api.github.com/search/users?q=${WHAT_WHOULD_GO_HERE}&sort=followers&order=desc`

仅供参考,我也在尝试获取流行的回购协议,这可以通过以下查询来实现,并且效果很好:

curl https://api.github.com/search/repositories\?q\=stars:\>1+language:javascript\&sort\=stars\&order\=desc\&type\=Repositories

2 个答案:

答案 0 :(得分:1)

您可以通过在Github API上指定关注者限制,存储库语言和页面来运行查询。如果您可以正确配置查询,则将获得所需的内容。

示例查询

`https://api.github.com/search/users?q=repos:followers:<1000&language:javascript&page=1&per_page=100`

例如,我可以获取具有2000个以上关注者的所有用户。这也引起了一种流行的用户。

`https://api.github.com/search/users?q=repos:followers:%3E2000&language:javascript&page=1&per_page=100`

响应

{
  "total_count": 321,
  "incomplete_results": false,
  "items": [
    {
      "login": "vim-scripts",
      "id": 443562,
      "node_id": "MDQ6VXNlcjQ0MzU2Mg==",
      "avatar_url": "https://avatars0.githubusercontent.com/u/443562?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/vim-scripts",
      ...
}

答案 1 :(得分:0)

摆弄我之后,我得到了答案:

curl https://api.github.com/search/users\?q\=followers:\>1000\&page\=1\&per_page\=10\&sort\=followers\&order\=desc

该查询基于Github自己的热门列表,该列表在其自己的URL中有一些线索,上面的查询返回的结果完全相同

https://github.com/search?o=desc&q=followers%3A%3E%3D1000&ref=searchresults&s=followers&type=Users

q查询参数仅需要以下条件:

  • 关注者:> 1000,

加上问题中所述的一些排序:

  • 排序:按照关注者人数
  • 顺序:后代