Twitch api in java?

How to check if user have stream on with Twitch Api in java? Any codes?

In general you want to be more specific about what you need help with but this should get you started.

i have error with this:
String json = API.readJsonFromUrl(“http://api.justin.tv/api/stream/list.json?channel=" + channelname + "”);
error:
[13:11:59 WARN]: java.net.MalformedURLException: no protocol: http://api.justin.tv/api/stream/list.json?channel=manwojciech
[13:11:59 WARN]: at java.net.URL.(URL.java:586)
[13:11:59 WARN]: at java.net.URL.(URL.java:483)
[13:11:59 WARN]: at java.net.URL.(URL.java:432)
how to repair this?

Take a look at https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md for the current endpoints relating to streams.

The Justin.tv API (api.justin.tv) was removed when Justin.tv shutdown last year thus it will not work.

ah ok i use this and i have this code

    public static Twitch_Stream getStream(String channelname) {
        try {
            String json = API.readJsonFromUrl("https://api.twitch.tv/kraken/streams?channel=" + channelname + "");

            Twitch_Stream stream = new Twitch_Stream();
            if (json.equalsIgnoreCase("[]")) {
                stream.setOnline(false);
                return stream;
            }
            JsonArray jb = gson.fromJson(json, JsonArray.class);
            JsonObject jo = (JsonObject) jb.get(0);
            stream.setOnline(true);
            stream.load(jo);
            return stream;
        } catch (Exception error) {
            error.printStackTrace();
        }

        return null;

    }

but i have error in :
JsonObject jo = (JsonObject) jb.get(0);
this line how to repair this? is my first time with json;/

The result of the /streams/channel= request is always a JSON object. For the streams you want to check in the array under the streams key (which only contains objects for the streams you have specified that are actually live).

Alternatively, if you always only want to check one channel, you can also use the /streams/:channel/ endpoint, where you also get a JSON object, but with only one stream object under the stream key (or null if not live).

i make this

    public static Twitch_Stream getStream(String channelname) {
        try {
            String json = API.readJsonFromUrl("https://api.twitch.tv/kraken/streams?channel=" + channelname);

            Twitch_Stream stream = new Twitch_Stream();
            if (json.equalsIgnoreCase("[]")) {
                stream.setOnline(false);
                return stream;
            }

            JsonArray jb = gson.fromJson(json, JsonArray.class);
            if (jb.size() != 0) {
                JsonObject jo = (JsonObject) jb.get(0);
                stream.setOnline(true);
                stream.load(jo);
            }

            return stream;
        } catch (Exception error) {
            error.printStackTrace();
        }

        return null;

    }

and i don’t have error but when i make
Twitch_Stream streamer = Twitch_API.getStream(“NickName”);
streamer.getName(); <— return me null;
and
streamer.isOnline(); <— return false (but stream is on)

We have no idea what your so called Twitch_Stream does.
If “NickName” is online, it infact returns a json, so the problem doesn’t seem to lie in this code.

Rather I think the mistake is made in Twitch_Stream.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.