import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
public static void main(String[] args) {
// @param {String} $token - String containing your API Key
// @param {String} $url - Encoded URI string container the URI you're targeting
// @param {Integer} $width - Integer indicating the width of your target render
// @param {Integer} $height - Integer indicating the height of your target render
// @param {String} $output - String specifying the output format, "image" or "json"
String token = "Your API Key";
String url = URLEncoder.encode("https://google.com");
// Construct the query params and URL
String query = "https://shot.screenshotapi.net/screenshot";
query += String.format("?token=%s&url=%s&width=%d&height=%d&output=%s",
token, url, width, height, output);
URL apiUrl = new URL(query);
// Call the API and save the screenshot
InputStream inputStream = apiUrl.openStream();
OutputStream outputStream = new FileOutputStream("./screenshot.png");
inputStream.transferTo(outputStream);