This is my code in java, and when i call it he return 401, i need something more?
private boolean checkTwitchLiveStatus() {
String clientId = "the_client_id_from_the_app_manager";
String channelName = "my_channel_name";
try {
URL url = new URL("https://api.twitch.tv/helix/streams?user_login=" + channelName);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Client-ID", clientId);
conn.setRequestProperty("Accept", "application/vnd.twitchtv.v5+json");
int responseCode = conn.getResponseCode();
System.out.println("Codice di risposta dell'API di Twitch: " + responseCode); //responseCode is the code 401
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
String jsonResponse = response.toString();
System.out.println("Risposta JSON dall'API di Twitch: " + jsonResponse);
return jsonResponse.contains("\"type\":\"live\"");
}
} catch (IOException e) {
e.printStackTrace();
}
return false; // Default: live non attiva
}