How to verify if a Twitch channel is currently broadcasting

I’m trying to build a Java application that can detect whether a specific Twitch streamer is currently online. The goal is to get a boolean response - true when they’re streaming and false when they’re not. I’m using minimal json library for parsing the API response.

Here’s what I’ve written so far:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import com.eclipsesource.json.JsonObject;

public class StreamChecker {

    public static void main(String[] args) throws Exception {
        ChatBot myBot = new ChatBot();
        myBot.setVerbose(true);
        myBot.connect("irc.twitch.tv", 6667, "mytoken");
    }
    
    public boolean checkIfLive() {
        try {
            URL apiUrl = new URL("https://api.twitch.tv/kraken/streams/streamerName");
            URLConnection connection = apiUrl.openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String response = reader.readLine();
            reader.close();
            JsonObject responseJson = JsonObject.readFrom(response);
            return (!responseJson.get("stream").isNull()) ? true : false;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return false;
    }
}

When the method returns false, should I expect to see “false” printed somewhere in the console output automatically?

The Kraken API has been deprecated for a long time. You should switch to the Helix API and implement the required authentication headers, as your current approach will not work due to the discontinuation of the previous endpoint. To use the new API, be sure to register your application for a Client ID and OAuth tokens. The endpoint to request whether a streamer is live will now be https://api.twitch.tv/helix/streams?user_login=streamername, where you will need to add Client-ID and Authorization headers to your requests. Additionally, your current method won’t automatically print any output. To see the boolean result, include System.out.println(checkIfLive()) in your main method. Note that the response structure has also changed; you should check if the data array is empty rather than checking for a null stream field.