有什么链接可以显示GitHub中的所有公共仓库吗? [英] is there any link to show all public repositories in GitHub?

查看:332
本文介绍了有什么链接可以显示GitHub中的所有公共仓库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,我试图获得GitHub中所有公共仓库的列表,但我没有找到任何链接。



例如在Sourceforge中,您可以根据类别或Google代码列出所有项目,您可以搜索所有项目的所有项目。



是的,我尝试使用关键字(如*或%)搜索或为空字符串,但您只能看到此页面 https://github.com/search?q=&type=Everything&repo=&langOverride=&start_value=1

解决方案

您可以使用以下请求在github中列出所有存储库:

https://api.github.com/repositories?since=0



它会返回作为JSON数组的第一个nid> 0的存储库。
您应该处理这个n,存储id。当您到达页面的末尾时,您只需再次输入since = lastId:
即可: /api.github.com/repositories?since=300rel =nofollow> https://api.github.com/repositories?since=300



这是我发现列出所有存储库的唯一方式,因为SEARCH api每个搜索有1000个回购的限制。
如果您打算处理所有回购,您应该准备应付费率限制:

https://developer.github.com/v3/rate_limit/



经过身份验证的用户获得更好的限制,你可以使用access_token(查看文档)。小心,不要过多地请求。
如果您需要过滤仓库,则需要为每个仓库执行额外的查询(以搜索API)。准备好处理超过一千万个知识库。
Java示例:(with javax.json.Json)

  int id = 0; 
do {
URL url = new URL(https://api.github.com/repositories?since=+ id +& access_token =+ oauth);
//实现callApi,比如Json.createReader(url.openStream()),但是如果限制达到
,请让它休眠一分钟尝试(JsonReader rdr = callApi(url)){
JsonArray results = rdr.readArray();
for(JsonObject result:results.getValuesAs(JsonObject.class)){
id = result.getInt(id);
String name = result.getString(name);
boolean priv = result.getBoolean(private);
...做任何你想做的事情......
}
}
} while(some stop condition);

祝你好运,我失去了一些时间去发现它。


Yesterday, I was trying to get a list of all public repositories in GitHub, but I didn't find any link.

And for example in Sourceforge you can list all proyects by categories or in Google code you can search all for all proyects.

Yes, I tried to search with keywords like as "*" or "%" or empty string, but you only see this page https://github.com/search?q=&type=Everything&repo=&langOverride=&start_value=1

解决方案

You can list all repositories in github using the following request:

https://api.github.com/repositories?since=0

it will return the first "n" repositories of id>0 as a JSON Array. You should process this "n", storing the "id". When you reach the end of the "page", you just hit again with since=lastId: for example:

https://api.github.com/repositories?since=300

This is the ONLY way I discovered to list ALL repositories, because the SEARCH api has a limit of 1000 repos per search. If you intend to process ALL repos, you should be prepared to cope with the rate-limit:

https://developer.github.com/v3/rate_limit/

Authenticated users get better limits, you can use an access_token (look at the documentation). BE CAREFUL, DON´T PUSH TOO MANY REQUESTS. If you need to filter the repos, you will need to perform an extra query (to search API) for each repo. Be prepared to deal with more than ten million repositories. Java Example: (with javax.json.Json)

int id=0;
do {
    URL url = new URL("https://api.github.com/repositories?since="+id+"&access_token="+oauth);
    // implement callApi such as Json.createReader(url.openStream()), but please make it sleep for a minute if the limit got reached        
    try (JsonReader rdr = callApi(url)) {
        JsonArray results = rdr.readArray();
        for (JsonObject result : results.getValuesAs(JsonObject.class)) {
            id = result.getInt("id");
            String name = result.getString("name");
            boolean priv = result.getBoolean("private");
            ... do whatever you want...
        }
    }
} while (some stop condition);

Good Luck, I lost some time to discover this.

这篇关于有什么链接可以显示GitHub中的所有公共仓库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆