[英]How can i connect to the github enterprise repository through java code?
I want to know how can i get the list of all the repositories present in my github enterprise(private). 我想知道如何获取我的github企业版(私有)中存在的所有存储库的列表。 I am unable to identify how should i use my personal access token to get authentication through java code. 我无法确定我应该如何使用我的个人访问令牌通过Java代码获得身份验证。
I have already tried with public repositories and i am able to use everything in that but i am unable to do this with my enterprise github. 我已经尝试使用公共存储库,并且能够使用其中的所有内容,但是无法使用我的企业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);
}
}
Best way do do that in java without the burden of rest authent is to use one of the Java API available. 在Java中做到这一点的最好方法是,使用剩下的Java API之一,而无需进行剩余身份验证。 This github page list all the APIs : 这个github页面列出了所有API:
https://developer.github.com/v3/libraries/ https://developer.github.com/v3/libraries/
And you have 2 java intersting API: 并且您有2个Java Intersting API:
egit-github : https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core egit-github: https : //github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core
and 和
kohsuke : http://github-api.kohsuke.org/ kohsuke: http ://github-api.kohsuke.org/
egit-github seems quite easy to work with... egit-github似乎很容易使用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.