简体   繁体   English

如何通过Java代码连接到github企业存储库?

[英]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.

相关问题 如何连接到Apache James的用户存储库并通过Java代码检索用户列表? - How can I connect to Apache James' user repository and retrieve a list of users through Java code? 如何使用Java和github API连接到github存储库 - How to connect to github repository using java and github api 如何检测企业 Java 项目(Java + JSP + Javascript)中的死代码? - How can I detect dead code in an enterprise Java project (Java + JSP + Javascript)? 如何将本地项目连接到github仓库 - How to connect local project to github repository 如何使用liberty.java将Watson Conversation连接到我的Web应用程序(github)? - How can I connect Watson Conversation to my webapp (github) using liberty.java? 如何通过Java代码更改TextView的位置? - How can i change the position of a TextView through Java code? 如何使用egit-github Java库登录Github? - How can I login to Github with the egit-github Java library? 如何使用Java代码连接到调制解调器路由器 - How can connect to modem router in java code 如何使用Java在GitHub存储库中以编程方式移动文件? - How to move a file programatically in a GitHub repository with Java? 如何使用 Java 访问 GitHub 中的存储库名称? - How to access the repository names in GitHub with Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM