# Set stream title and game in Python

**URL:** <https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030>\
**Category:** API\
**Created:** [September 16, 2017, 4:47pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030 "2017-09-16T16:47:29Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 16, 2017, 4:47pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/1 "2017-09-16T16:47:29Z")

</div>

I don’t understand, what am I doing wrong?

```
url = "https://api.twitch.tv/kraken/channels/my_channel"

headers = {"Client-ID" : ""+ config.CLIENT_ID +"", "Authorization": "OAuth "+config.CHAN_OAUTH}
data = {"channel": {"status": "The Finalest of Fantasies"}}

response = requests.put(url=url, headers=headers, params = data)

```

I’m getting a 401 response error for (apparently) no reason.

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [September 16, 2017, 4:49pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/2 "2017-09-16T16:49:13Z")

</div>

Does your OAuth token have the channel\_editor scope?

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 16, 2017, 4:54pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/3 "2017-09-16T16:54:12Z")

</div>

I didn’t think about that, so probably it doesn’t. How can I fix that?

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [September 16, 2017, 5:53pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/4 "2017-09-16T17:53:57Z")

</div>

Request it using one of the user access token flows: [https://dev.twitch.tv/docs/authentication](https://dev.twitch.tv/docs/authentication)

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 17, 2017, 1:13pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/5 "2017-09-17T13:13:45Z")

</div>

So, I need to act like this:

```
url = "https://api.twitch.tv/kraken/oauth2/authorize"
params = {"Client-ID" : ""+ config.CLIENT_ID +"", "scope" : "channel_editor"}
config.resp = requests.get(url=url, headers=params)

```

Before setting the status as I was doing before.  
Am I right?

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 1:38pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/6 "2017-09-17T13:38:44Z")

</div>

@Pinasu - First of all, what version are you trying to use? v3, v5 or the new twitch API?

Since you wrote

[https://api.twitch.tv/kraken/channels/my\_channel](https://api.twitch.tv/kraken/channels/my_channel)

It looks like its v3 or v5.

But you haven’t specified which version.

You solve a lot of obfuscated problems by setting API version.

It also dictates the authentication process.

Which doc are you following?

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 17, 2017, 2:26pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/7 "2017-09-17T14:26:12Z")

</div>

I’m using v5, so I’m getting all my infos from [here](https://dev.twitch.tv/docs/v5).

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 2:28pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/8 "2017-09-17T14:28:35Z")

</div>

Looks like this end point

> **[Channels Reference](https://dev.twitch.tv/docs/v5/reference/channels#update-channel)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 17, 2017, 2:30pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/9 "2017-09-17T14:30:31Z")

</div>

That’s right, but I was getting Error 401.

`To update other parameters: channel_editor`

So I was trying to get the right token as @george suggested.

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 2:31pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/10 "2017-09-17T14:31:27Z")

</div>

First of all, you need to add `api_version=5` to your URL in that case, I think.  
Or apply the header `application/vnd.twitchtv.v5+json` header, as described here:

[https://dev.twitch.tv/docs/v5/guides/using-the-twitch-api#requests](https://dev.twitch.tv/docs/v5/guides/using-the-twitch-api#requests)

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 2:37pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/11 "2017-09-17T14:37:56Z")

</div>

Also found:

> 401 Unauthorized. The OAuth token does not have the correct scope or does not have the required permission on behalf of the specified user

And @george is right you need `channel_editor` as described here:

> **[Authentication](https://dev.twitch.tv/docs/authentication/)**
>
> Authentication

> channel\_editor Write channel metadata (game, status, etc).

But you still gettng 401?

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 2:40pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/12 "2017-09-17T14:40:17Z")

</div>

Since its from Python, you using app access tokens?

> **[Apps & Authentication](https://dev.twitch.tv/docs/authentication#oauth-client-credentials-flow-app-access-tokens)**
>
> Apps & Authentication

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 17, 2017, 2:48pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/13 "2017-09-17T14:48:49Z")

</div>

I just added the API version in the header and I’m trying to get the right token as follows:

```
url = "https://api.twitch.tv/kraken/oauth2/authorize"
params = {"Client-ID" : ""+ config.CLIENT_ID +"",
          "Accept" : "application/vnd.twitchtv.v5+json", 
          "scope" : "openid channel_editor"}
config.resp = requests.get(url=url, headers=params)

```

But I’m getting “Bad request”, so I’m probably miswriting something.

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 2:54pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/14 "2017-09-17T14:54:37Z")

</div>

Is `scope` a header? I thought it was an URL query parameter. Hm.

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 2:57pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/15 "2017-09-17T14:57:04Z")

</div>

Also which “Procedure” you using?

> **[Apps & Authentication](https://dev.twitch.tv/docs/authentication#getting-tokens)**
>
> Apps & Authentication

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 17, 2017, 3:08pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/16 "2017-09-17T15:08:38Z")

</div>

I’m using the OIDC Authorization Code Flow (ID Tokens and User Access Tokens) one.  
Setting the scope as parameter still gives me 400 Bad request.

EDIT: I’m missing the redirect URI, so that’s probably my issue. I really don’t remember what was my URL when I registered my app, so I’m trying to figure out how to get that.

---

<div class="post-metadata">

**Author:** ![corgrath](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@corgrath](https://discuss.dev.twitch.com/u/corgrath)\
**Post date:** [September 17, 2017, 3:14pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/17 "2017-09-17T15:14:42Z")

</div>

I think its found here, for your app:

> **[Twitch](https://glass.twitch.tv/console/apps)**
>
> Twitch is the world's leading video platform and community for gamers.

---

<div class="post-metadata">

**Author:** ![Pinasu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pinasu/32/3332_2.png) [@Pinasu](https://discuss.dev.twitch.com/u/Pinasu)\
**Post date:** [September 17, 2017, 3:24pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/18 "2017-09-17T15:24:11Z")

</div>

Yes I already found it, thanks anyway.

Setting the redirect uri as header param seemed to be the trick, so I’m now able to receive the 200 code from the token request. Now I don’t understand what am I supposed to do after obtaining my  
token.

EDIT: from what I read, I need to send a new request with the “client\_secret” code, sent me from the server.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [October 17, 2017, 3:24pm UTC](https://discuss.dev.twitch.com/t/set-stream-title-and-game-in-python/12030/19 "2017-10-17T15:24:29Z")

</div>

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