Need help setting status and title in vb.net

        Dim myReq As HttpWebRequest
        Dim myResp As HttpWebResponse

        myReq = HttpWebRequest.Create(Twitch_BaseURL & "channels/" & Twitch_UserID)
        myReq.Method = "PUT"
        myReq.ContentType = "application/json"
        myReq.Headers.Add("Client-ID:" & Twitch_ClientID)
        myReq.Accept = "application/vnd.twitchtv.v5+json"
        Dim myData As String = "channel[status]=Please+work!&channel[game]=Something"
        myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
        myResp = myReq.GetResponse
        Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
        Dim myText As String
        myText = myreader.ReadToEnd

On the line myResp = myReq.GetResponse I get an #500 Internal Server Error

I tried different methods but doesn’t get it to work,
Client-ID, Twitch_BaseURL and Twitch_UserID are fine, because they work on request methods.

Please advise me.

One issue I see is that you are setting your content type for the request to application/json but you are not sending json in the request body.

When I change that to text/plain I get another error 401 not permitted. (or something like that in English :slight_smile: )

do I need to login to my user account also to change the status and title, and if so, how do I do that?

You need to send an Authorization header with an OAuth token that has the appropriate scope to make the changes. The docs say what you’ll need https://dev.twitch.tv/docs/v5/reference/channels/#update-channel

What @Dist pointed out is correct: you’re missing the Authorization header.

But also your Content-Type header should be application/x-www-form-urlencoded as that is the format you’re using in your request body. Alternatively make your body JSON and use application/json like in your original example.

Thanks, is the Authorization the same as the key you put in i.e. OBS studio?

No. See https://dev.twitch.tv/docs/v5/guides/authentication/

Thanks for the help.

To help others, this should then be the final procedure.

Public Sub SetChannelInfo(Game As String, Status As String)
    Try

        Dim myReq As HttpWebRequest
        Dim myResp As HttpWebResponse
        myReq = HttpWebRequest.Create(Twitch_BaseURL & "channels/" & Twitch_UserID)
        myReq.Method = "PUT"
        myReq.ContentType = "text/plain"
        myReq.Headers.Add("Client-ID:" & Twitch_ClientID)
        myReq.Headers.Add("Authorization: OAuth " & My.Settings.Twitch_AuthenticationCode)
        myReq.Accept = "application/vnd.twitchtv.v5+json"
        Dim myData As String = "channel[status]=" & Status & "&channel[game]=" & Game
        Dim Buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(myData)
        myReq.GetRequestStream.Write(Buffer, 0, Buffer.Count)
        myResp = myReq.GetResponse
        Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
        Dim myText As String
        myText = myreader.ReadToEnd
    Catch ex As Exception
        MsgBox("Some error on setting Channel Info")
    End Try
End Sub

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