Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda