Jump to content

Check the status of a twitch channel inside a mod?


OCDiary

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.