Updating channel title and game from c# application

Hey there, i have been trying for the past hours to get this to work but so far no success. this is the code im using (i dont get any execption)

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(prefix + requestUrl);

        request.Method = "POST";
        request.Accept = "application/vnd.twitchtv.v3+json";
        request.Headers.Add($"Authorization: OAuth {OAuthKey}");
        var formattedData = JsonConvert.SerializeObject(obj);
        UTF8Encoding encoding = new UTF8Encoding();
        byte[] buffer = encoding.GetBytes(formattedData);
        Stream reqstr = request.GetRequestStream();
        reqstr.Write(buffer, 0, buffer.Length);
        reqstr.Close();

Thank you for any help!

What does the API response from Twitch say? You’re also trying to send JSON, but are not setting that as the Content-Type. You need to add a Content-Type: application/json header if you’re POSTing JSON. You might also try using a url-encoded POST instead of JSON. Another user was successful posting a url-encoded form to Twitch at .NET Authentication and Authroization

Hey @night thank you for your reply, i have added the contenttype to my request and tried to see whats the reponse returns and im getting: The remote server returned an error: (404) Not Found.

the link looks like this: https://api.twitch.tv/kraken/channels/delf0?channel[status]=WPF C# dsfdsfs!&channel[game]=Programming&channel[delay]=0

I will try your link suggestion and give you some feedback!

@night Hey, i found where the problem was. I was not authenticating my app with twitch and i was passing the wrong OAuth … Now is solved, if anyone is looking for the same here is the code i used:

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(prefix + requestUrl);

            request.ContentType = "application/json";
            request.Method = "PUT";
            request.Accept = "application/vnd.twitchtv.v3+json";
            request.Headers.Add("Authorization: OAuth " + accessToken);
            var formattedData = JsonConvert.SerializeObject(obj);
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] buffer = encoding.GetBytes(formattedData);
            Stream reqstr = request.GetRequestStream();
            reqstr.Write(buffer, 0, buffer.Length);
            reqstr.Close();
            string ret;

            WebResponse response = null;
            try
            {
                response = request.GetResponse();
            }
            catch (WebException ex)
            {
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadRequest)
                {
                }
                response = (WebResponse)ex.Response;
            }

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