Last active
December 10, 2024 01:10
-
-
Save steppat/d6fc9a8fa90f0c4e5f6bbf23c3e5d89e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URI; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
class SevenDaysOfCodeJavaDay1 { | |
public static void main(String[] args) throws Exception { | |
String apiKey = "<sua chave>"; | |
URI apiIMDB = URI.create("https://imdb-api.com/en/API/Top250TVs/" + apiKey); | |
HttpClient client = HttpClient.newHttpClient(); | |
HttpRequest request = HttpRequest.newBuilder().uri(apiIMDB).build(); | |
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | |
String json = response.body(); | |
System.out.println("Resposta: " + json); | |
} | |
} |
Pessoal, a api do desafio hoje é paga.
Estou usando essa para fazer o desafio. Gratuita e muito bem documentada.
https://developer.themoviedb.org/docs
Pessoal, a api do desafio hoje é paga. Estou usando essa para fazer o desafio. Gratuita e muito bem documentada. https://developer.themoviedb.org/docs
Obrigadão!
Gente, usei a Api que o pessoal mandou nos comentários acima: https://developer.themoviedb.org/docs
Para quem estiver tendo dificuldades de conectar na API, cheguei a fazer, caso queiram dar uma olhada.
Meu repositório: https://github.com/CaiquePiazzaroli/7Days-To-Code.git
`
public class ApiTmdbClient {
private String apiUrl;
private HttpClient client;
private HttpRequest request;
private HttpResponse<String> response;
private String json;
//TBDB api connection
public ApiTmdbClient(String token, String apiUrl) throws URISyntaxException, IOException, InterruptedException {
//Criando o cliente
this.apiUrl = apiUrl;
this.client = HttpClient.newBuilder().build();
//Criando o request
this.request = newBuilder()
.uri(new URI(this.apiUrl))
.header("Authorization", "Bearer " + token)
.GET()
.build();
//Criando a response
this.response = client.send(request, HttpResponse.BodyHandlers.ofString());
this.json = this.response.body();
}
public String getJson() {
return json;
}`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O meu só imprimi o primeiro filme no console, mas qdo olho o response.body o arquivo está completo...Não sei pq não imprimiu tudo..
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
}