[Java] New Twitch API - Streams return empty Json when ?user_id is set

Hello everyone,

I have been working on a Java project to work with the Twitch API. I have been able to call the User endpoint without issue. However when I call the streams endpoint with a user_id parameter I get an empty Json response. Can anyone help me figure out where the issue is?

I was expecting at least a Type member of “offline”, but as noted I get {“data”:[],“pagination”:{}}. I tested the same connection without the appended ?user_id and got a response with data. Should the ?user_id=157552165 be added outside of the URL itself?

This is the connection code. I pulled out some of the URL building and if statements, but commented on what the values are where relevant. If more info is needed let me know and I can post it. I obtained the user_id from the api directly so that should be the correct value.

assert requestUrl != null;
connection = (HttpURLConnection) requestUrl.openConnection(); //URL = https://api.twitch.tv/helix/streams?user_id=157552165
connection.setRequestMethod(“GET”);
connection.setRequestProperty(“Authorization”, "Bearer " + accessToken);
connection.connect();

int code = connection.getResponseCode(); //Response code returns as 200

JsonElement root = jp.parse(new InputStreamReader((InputStream) connection.getContent()));
JsonObject rootobj = root.getAsJsonObject(); // returns {“data”:[],“pagination”:{}}

The endpoint returns a list of Streams matching the criteria you specified (in this case a single user ID). If the user is not live, he does not have a Stream, and so there’s nothing to add to the array. There’s no entries for offline channels returned; you’ll need to check if they exist in the response.

TLDR: Working as expected. Not live = missing in response array entirely.

So with the new API there is no way to interact with a users stream information when they are not live? In other words they cannot set their upcoming stream title prior to going live?

Sadly no, but you can still use v5’s endpoints:
PUT https://api.twitch.tv/kraken/channels/<channel ID> to update a channel
GET https://api.twitch.tv/kraken/channels/<channel ID> to get a channel’s current information
(More at https://dev.twitch.tv/docs/v5/reference/channels/)

Helix is missing a lot of stuff, that is the reason v5 still remains functional. If you need to use enpoints not available in Helix, check Kraken.

I was considering just that. It doesnt look like I can use a single access token to do both though. Unless the scopes translate somehow between end points.

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