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”:{}}