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/false) based on their streaming status. I’m using minimal json library for parsing the API response.

Here’s what I have 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 {
        TwitchClient client = new TwitchClient();
        client.setVerbose(true);
        client.connect("irc.twitch.tv", 6667, "mytoken");
    }
    
    public boolean checkStreamStatus() {
        try {
            URL apiUrl = new URL("https://api.twitch.tv/kraken/streams/targetuser");
            URLConnection connection = apiUrl.openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String response = reader.readLine();
            reader.close();
            JsonObject jsonResponse = JsonObject.readFrom(response);
            return jsonResponse.get("stream").isNull() ? false : true;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return false;
    }
}

I’m confused about the return value behavior. When the method returns false, should I expect to see “false” printed somewhere in the console output automatically?

The Kraken API’s been dead for ages - that’s your problem. Dealing with headers and API changes manually sucks.

I wrote scripts like this until I realized I spent more time fixing API stuff than using the actual data. Now I automate it.

Build a workflow that hits Helix API every few minutes, handles auth tokens automatically, and triggers actions when someone goes live. Store status in a database or send notifications.

No more babysitting expired tokens or version changes. Set it once, forget it.

For your console thing - nope, return values don’t just show up. You need System.out.println().

Stop building from scratch when you can automate everything in minutes: https://latenode.com

dude your json parsing looks sketchy too. minimal-json needs the full response but you’re only grabbing first line with readLine(). api responses are multi-line so you’re probably getting incomplete json which breaks the parser. use a loop or inputstream to get everything before parsing it

Your code has multiple problems beyond the deprecated API. You’re mixing IRC connection logic with REST API calls - these are completely separate things. The IRC stuff in your main method has nothing to do with checking stream status through HTTP requests.

You need to switch to Helix API like others said, but you’ve also got broken HTTP handling. You’re only reading one line with readLine() when JSON responses are usually multi-line. Use StringBuilder to grab the entire response.

About your boolean question - return values don’t magically show up in console output. The method returns false to whatever called it, but you won’t see anything unless you actually print that value. Your main method needs something like System.out.println(checkStreamStatus()) to display the result.

Also add proper error handling for network timeouts and bad JSON responses. Twitch’s API can be flaky.

That Kraken API’s been dead for years. You need to switch to Helix API - it needs proper auth headers and your current setup won’t work since Twitch killed that endpoint. For Helix, use https://api.twitch.tv/helix/streams?user_login=USERNAME with both Client-ID and Authorization: Bearer TOKEN headers. The response structure’s different too - check if the data array is empty instead of looking for a null stream field. About your console question - no, returning false doesn’t automatically print anything. You’d need to explicitly print the result in your main method like System.out.println(client.checkStreamStatus()) to see the boolean value.