Making Request to new twitch API in java

Hi, so I’ll start off with I have no idea what I’m doing, I am trying to do a lot of things. I have no experience with server requests but I am trying to make a discord bot that will monitor a group of people to see when they are online on twitch and post them to a server. So the part that I am not understanding at all is how to make a request form the twitch api in order to get the JSON of there status. I am currently looking at this link, and it shows this snippet

curl -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET ''

So from my understanding I need to submit a request to the api following that forat with replacing the userid with the channel I would like to check. However, I have no idea how to do that. I copied the following java code

public static String executePost(String channelName){
    URL url;
    HttpURLConnection connection = null;

        //create connection
        url = new URL((""  + channelName));
        connection = (HttpURLConnection)url.openConnection();


        //Send request
        DataOutputStream wr = new DataOutputStream(

        //Get response
        InputStream is = connection.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        String line;
        StringBuffer response = new StringBuffer();
        while((line = rd.readLine()) != null){
        return response.toString();
    } catch (Exception e){
        return null;
    } finally {
        if (connection != null) {

So currently, I am trying to make an http request from java in order to get the JSON, but I have also read you that you need an authentication in the request, which I have no idea how I would do that. I set up my twitch application and have access to the client ID and secret ID, I just don’t know what to do with them. If anyone can give me an example or point me to sources to help learn more about this, I would be greatly appreciative!

For the API method you are calling, to put it simply, No authentication is required. Aside from a header containing a Client ID.

You are calling

Which is a GET request not a POST like in your snippet.
This should do what you need:

    url = new URL((""  + channelName));
    connection = (HttpURLConnection)url.openConnection();

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.