use*_*922 3 github github-api jcabi
我努力寻找一个简单的代码行,它使用oauth令牌从企业github读取文件内容,但是找不到这样的例子.
我试过https://github.com/jcabi/jcabi-github,但它不支持企业github?(也许我错了)
现在我正在尝试自我:
GitHubClient client = new GitHubClient("enterprise url");
GitHubRequest request = new GitHubRequest();
request.setUri("/readme");
GitHubResponse response = client.get(request);
Run Code Online (Sandbox Code Playgroud)
那又怎样?我只看到了一个getBody,也许我需要用一些json库来解析它?它必须更简单..我期待的东西像:repo.get(url).getContent()
最后通过阅读源代码弄清楚..
GitHubClient client = new GitHubClient(YOURENTERPRICEURL);
client.setOAuth2Token(token);
// first use token service
RepositoryService repoService = new RepositoryService(client);
try {
Repository repo = repoService.getRepository(USER, REPONAME);
// now contents service
ContentsService contentService = new ContentsService(client);
List<RepositoryContents> test = contentService.getContents(repo, YOURFILENAME);
List<RepositoryContents> contentList = contentService.getContents(repo);
for(RepositoryContents content : test){
String fileConent = content.getContent();
String valueDecoded= new String(Base64.decodeBase64(fileConent.getBytes() ));
System.out.println(valueDecoded);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3897 次 |
| 最近记录: |