Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

  • 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

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.