Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
Authenticate http call to GitHub APIs in java

I'm working on a project which requires to call GitHub APIs several times and I reached the limit of 60. I read that with authentication you get 5000 as limit but I can't understand how I can authenticate my requests in my java program. I got my authentication token on Github and this is the way I'm building the request in java:

// create client
HttpClient client = HttpClient.newHttpClient();

// create request
HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.github.com/repos/:owner/:repo/commits"))
                .build();

what should I add to the request to authenticate it? I tried adding the header authToken:myToken but it didn't work.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Solved:

Once I got the token on my GitHub profile > Settings > Developer Settings > Personal Access Tokens, I added the header `"Authorization: Bearer "myToken" " to the http request so the request becomes:

// create client
HttpClient client = HttpClient.newHttpClient();

// create request
HttpRequest request = HttpRequest.newBuilder().header("Authorization","Bearer <myToken>")
                .uri(URI.create("https://api.github.com/repos/:owner/:repo/commits"))
                .build();
over 4 years ago · Santiago Trujillo Report

0

You need to add Http request header Authorization to your request and the header should contain your token. So if your code is written on Java 11 or higher as it appears to be than you need to change your code to:

// create client
HttpClient client = HttpClient.newHttpClient();

// create request
HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.github.com/repos/:owner/:repo/commits"))
                .header("Authorization", "your-tocken")
                .build();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!