Error while running sample code

18 views
Skip to first unread message

nakul sharma

unread,
Sep 10, 2024, 12:44:58 AM9/10/24
to GitHub Java API (http://github-api.kohsuke.org/)
Hi All,

Using the code mentioned in https://github-api.kohsuke.org/, I tried connecting to github.

However the error message is as follows :-

java.io.IOException: Failed to resolve credentials from ~/.github or the environment.

complete code is as follows

public class MavenProject1 {
    public void connectGit()throws Exception {
       
            GitHub github = GitHub.connect();

GHRepository repo = github.createRepository(
  "new-repository","this is my new repository",
  "https://www.kohsuke.org/",true/*public*/);
repo.addCollaborators(github.getUser("abayer"),github.getUser("rtyler"));
repo.delete();

    }
public static void main(String args[]){
    try{
    new MavenProject1().connectGit();
    }
    catch(Exception e){
        System.out.println(e);
    }
}
   
}

nakul sharma

unread,
Sep 10, 2024, 12:46:52 AM9/10/24
to GitHub Java API (http://github-api.kohsuke.org/)
Maven and git is also installed on the system.

The dependencies are added to the pom.xml file also.

There are  no compilation errors but only a run-time error.

Sukumaran V

unread,
Sep 10, 2024, 12:59:34 AM9/10/24
to GitHub Java API (http://github-api.kohsuke.org/)
Hi Nakul

You need to have your Access Token placed in your home directory with file name .github

The file content should be like : 

oauth=<your-token>

Hope this solution helps you. Thanks.
Reply all
Reply to author
Forward
0 new messages