java - 如何通过 java 代码连接到 github 企业存储库?
问题描述
我想知道如何获取我的 github 企业(私有)中存在的所有存储库的列表。我无法确定我应该如何使用我的个人访问令牌通过 java 代码进行身份验证。
我已经尝试过使用公共存储库,并且我可以使用其中的所有内容,但我无法使用我的企业 github 执行此操作。
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.apache.commons.codec.binary.Base64;
public class httpget {
public static void main(String args[]) throws IOException, ParseException,JSONException
{
URL url=new URL("https://github---.com/api/v3/...");
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
String token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String authString="Basic"+Base64.encodeBase64(token.getBytes());
conn.setRequestProperty("Authorization", authString);
conn.connect();
String inline="";
Scanner sc = new Scanner(url.openStream());
while(sc.hasNext())
{
inline+=sc.nextLine();
}
sc.close();
System.out.println(inline);
}
}
解决方案
在 java 中做到这一点而不需要休息 authent 的最好方法是使用可用的 Java API 之一。这个 github 页面列出了所有的 API:
https://developer.github.com/v3/libraries/
你有 2 个 java 有趣的 API:
egit-github:https ://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core
和
kohsuke:http: //github-api.kohsuke.org/
egit-github 似乎很容易使用......
推荐阅读
- angular - 打到最后一个退格键时如何不去掉标签输入芯片?
- python - 使用具有已实现功能的 Pandas DF
- sql - 在 SQL Server 中将值转换为列
- java - 我必须为活动充值才能显示自定义适配器 [Andoid Studio]
- html - 在基于 Chromium 的浏览器中使用“text-align:center”时如何避免文本轻微偏移?
- json - 将 curl POST 请求转换为 curl JSON POST 请求
- python - 如何在python列表中的字典中获取一个值并进一步从中索引一个值
- git - Git / GitHub:如何将新的本地仓库放入空的远程仓库
- physics - 将角度转换为速度
- go - 在测试 mux.Vars() 返回 nil 而不是预期的地图