Chatbot setting stream title

Hello everyone.
I’m trying to get my chatbot to set the title of a stream via chat commands.
I registered the application with the scopes channel_editor and user_subscriptions and got the authtoken it returned. Accessing the subscriptions with a get-request works, but everytime I try to set the streamtitle it returns a 401. I should have permission to do this though.

For the bot I use Java and this is the code snipped thats supposed to change the title.

	String url = "https://api.twitch.tv/kraken/channels/<name>?oauth:<token>";
    URL obj = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) obj.openConnection();

    conn.setRequestProperty("Accept", "application/vnd.twitchtv.v2+json");
    conn.setRequestMethod("PUT");
    conn.setDoOutput(true);
      
    String data = "channel[status]=Please+work!&channel[game]=Something";
    OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
    out.write(data);
    out.flush();

    for (Entry<String, List<String>> header : conn.getHeaderFields().entrySet()) {
        System.out.println(header.getKey() + "=" + header.getValue());
    }

Am I doing something wrong?

String url = "https://api.twitch.tv/kraken/channels/<name>?oauth:<token>";

should be

String url = "https://api.twitch.tv/kraken/channels/<name>?oauth_token=<token>";

to start with.

1 Like

Oh thank you for that. I must have overlooked that.
I get a 400- bad request error now

I can’t figure it out. I’m trying to get it running for over a week now but I don’t even know whats wrong.
I just get this as response:

Status=[400 Bad Request]
null=[HTTP/1.1 400 Bad Request]
Server=[nginx]
X-Request-Id=[c69b67ea980928e294d9a42a1f498dd7]
X-Runtime=[0.033893]
Connection=[keep-alive]
X-MH-Cache=[appcache2; M]
Date=[Fri, 04 Jul 2014 16:00:06 GMT]
Via=[1.1 varnish]
Accept-Ranges=[bytes]
X-Varnish=[551089609]
X-UA-Compatible=[IE=Edge,chrome=1]
Cache-Control=[max-age=0, private, must-revalidate]
Vary=[Accept-Encoding]
Content-Length=[83]
Age=[0]
X-API-Version=[2]
Content-Type=[application/json; charset=utf-8]

Are you setting conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");?

1 Like