gpt4 book ai didi

github-api - Github Java API-搜索仓库

转载 作者:行者123 更新时间:2023-12-03 13:11:50 24 4
gpt4 key购买 nike

我想根据大小和关键字参数搜索Github存储库。这是我编写的Java代码:

package searchTest;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.egit.github.core.SearchRepository;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.RepositoryService;

public class GithubSearch {
private static Map<String, String> searchQuery = new HashMap<String, String>();

public static void main(String[] args) throws IOException {
GitHubClient client = new GitHubClient();
client.setCredentials("username", "password");
RepositoryService service = new RepositoryService(client);
searchQuery.put("keyword","microsoft");
searchQuery.put("size","304");
List<SearchRepository> searchRes = service.searchRepositories(searchQuery);
System.out.println("Search result "+searchRes.toString());
}
}

但是我得到的输出是空的:
Search result []

我检查了 GitHub Java API javadoc,但找不到解决方案。

谢谢!

最佳答案

尝试jcabi-github(我是其开发人员之一):

final Github github = new RtGithub();
final JsonResponse resp = github.entry()
.uri().path("/search/repositories")
.queryParam("q", "java").back()
.fetch()
.as(JsonResponse.class);
final List<JsonObject> items = resp.json().readObject()
.getJsonArray("items")
.getValuesAs(JsonObject.class);
for (final JsonObject item : items) {
System.out.println(
String.format(
"repository found: %s",
item.get("full_name").toString()
)
);
}

完整示例在这里: https://github.com/jcabi/jcabi-github/tree/master/examples/search-repos

关于github-api - Github Java API-搜索仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com