C# Update Game & Title forbidden

Hello, I want to update the title and the game in C#, but I get the error forbidden.
Here’s my C# httpClient code:

    using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod("PUT"), "https://api.twitch.tv/kraken/channels/" + Settings.Default.ChannelID))
                {
                    request.Headers.TryAddWithoutValidation("Accept", "application/vnd.twitchtv.v5+json");
                    request.Headers.TryAddWithoutValidation("Authorization", "OAuth " + Settings.Default.ChannelToken);
                    request.Headers.TryAddWithoutValidation("Client-ID", Settings.Default.ClientID);

                    request.Content = new StringContent("{\"channel\": {\"status\": \"Test\", \"game\": \"Overwatch\", \"channel_feed_enabled\": true}}", Encoding.UTF8, "application/json");

                    var response = await httpClient.SendAsync(request);
                    Console.WriteLine(response.StatusCode);
                }
            }

The channelID, OAuth token and client id is saved in the application settings, and it shouldn’t be a problem, because the TwitchLib library works perfectly fine.
I printed out the variables in the console and none of the variables is empty.

Thanks in advance

Did you get a body with your response?

It should provide error information

I’m fairly new to C# so… can you explain how I do that?
I tried it using this command:
var body = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(body);

But the response is

????D?K
?0D?"?."??x?@?6~@-??J???*.g^?,?-:’?b-?P???6U???f?tr?K(#?X??,k\ab?K?????a>????????e?P???

The commands var body = response.Content.ReadAsStringAsync(); and var body = response.Content; doesn’t tell me anything interesting.

You need to enable GZIP compression.

That response hasn’t been ungzipped.

At a guess, that usually looks like the authorisation error, which means the oAuth key you used doesn’t have the required scopes to update the channel

Which for:

Is channel_editor scope

Oh yes sorry, I forgot to tell about that. I already visited that link (actually I’m using the public documentation all the time) and I also saw I need that scope.
That’s my request url:

https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=“myClientID”&redirect_uri=http://localhost:8243&scope=chat:read+chat:edit+channel:moderate+user_read+channel_editor

That should be fine, or am I wrong? The channel_editor scope is also included.

Get GZIP compression enabled for your call (to update the channel) and you’ll be able to read the error body response.

You can also totally remove channel_feed_enabled from your JSON as the feed is dead/removed feature, it’s just in the docs for completeness

If you call channel_feed_enabled you need channel_editor from the channel you are trying to update.

Otherwise

You need a key with channel_editor on for YOU and YOU are also an editor on the target channel.
-OR-
You need a key with channel_editor on for the channel you wish to update.

Unless you are trying to update your own personal channel, I anticipate you have the wrong owner of the key

Ok well… looks like that was the problem…
I removed the channel_feed_enabled from the json and it looks like it’s working now. Thank you very much! I spent my last view hours with that problem :expressionless:
You saved me! Thank you :smiley:

1 Like

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