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 GoogleBooksApiExemplo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Digite o título do livro:");
String tituloLivro = scanner.nextLine();
String apiKey = "minhaChaveDagoogle";
String apiUrl = "https://www.googleapis.com/books/v1/volumes?q=" + tituloLivro.replace(" ", "+") + "&key=" + apiKey;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiUrl))
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Resposta da API: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}