Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda