Posted January 30, 20178 yr Hi, I want to perform a simple check on a twitch channel within my mod, all it needs to do is check if a twitch channel is online. I have tried some things I can think of but none even remotely worked and now I am completely stumped and dont know where to start. Any help would be greatly appreciated Thanks OC
January 31, 20178 yr Why? I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
February 4, 20178 yr Author Hi LexManos, Sorry its take some time been mental busy. I want to have the mod check if a channel is live and if so will perform said action in game. Thank you diesieben07 I had looked at that previously, but couldnt work out how to just simply check if the site was live without a clientID. What I want is something like this: public static boolean checkIfOnline(String channel){ String channerUrl = "https://api.twitch.tv/kraken/streams/" + channel; String jsonText = readFromUrl(channerUrl);// reads text from URL JsonParser parser = new JsonParser(); JsonObject json = parser.parse(jsonText).getAsJsonObject(); return !json.get("stream").isJsonNull(); } private static String readFromUrl(String url) throws IOException { URL page = new URL(url); StringBuilder sb = new StringBuilder(); Scanner scanner = null; try{ scanner = new Scanner(page.openStream(), StandardCharsets.UTF_8.name()); while (scanner.hasNextLine()){ sb.append(scanner.nextLine()); } }finally{ if (scanner!=null) scanner.close(); } return sb.toString(); } Except that method no longer works. I would ideally just have a boolean that is true when the channel is live that I can then use elsewhere in the mod. Thanks so much for your help OC
February 5, 20178 yr Author Hey Diesieben07, I had a funny feeling you would say that, I just didnt want to have to setup a redirect uri and everything. Shame it was so simple but now seems a lot more of a pain to do just a simple online check. Thanks again OC
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.