Could someone help me how to connect to Github & how to upload a document using Java program ?
I want to connect to Github and once its connected I want to upload a document to github using Java program.
Many thanks, Raju
Could someone help me how to connect to Github & how to upload a document using Java program ?
I want to connect to Github and once its connected I want to upload a document to github using Java program.
Many thanks, Raju
The simplest solution is to use one of the Github libraries. If you are interested in Java then you need to use this one.
First you need to authenticate using your Github account. Here is the sample from readme:
//Basic authentication
GitHubClient client = new GitHubClient();
client.setCredentials("user", "passw0rd");
//OAuth2 token authentication
GitHubClient client = new GitHubClient();
client.setOAuth2Token("SlAV32hkKG");
Then it depends on how you want to upload a document to Github. The simplest is to create a Gist. To do it use the following code:
GistFile file = new GistFile();
file.setContent("System.out.println(\"Hello World\");");
Gist gist = new Gist();
gist.setDescription("Prints a string to standard out");
gist.setFiles(Collections.singletonMap("Hello.java", file));
GistService service = new GistService();
service.getClient().setCredentials("user", "passw0rd");
gist = service.createGist(gist); //returns the created gist
Note Gists are publicly available so if you want to make it private you need to do it explicitly