# Get Stream Key with Python

**URL:** <https://staging-discuss.dev.twitch.com/t/get-stream-key-with-python/35342>\
**Category:** API\
**Created:** [December 11, 2021, 9:58pm UTC](https://staging-discuss.dev.twitch.com/t/get-stream-key-with-python/35342 "2021-12-11T21:58:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirhoseyndoran1](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@amirhoseyndoran1](https://staging-discuss.dev.twitch.com/u/amirhoseyndoran1)\
**Post date:** [December 11, 2021, 9:58pm UTC](https://staging-discuss.dev.twitch.com/t/get-stream-key-with-python/35342/1 "2021-12-11T21:58:03Z")

</div>

Hi guys I want to get **stream key** with Python but I am **very beginner** and I do not know exactly what I should do please guide me

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 12, 2021, 3:35pm UTC](https://staging-discuss.dev.twitch.com/t/get-stream-key-with-python/35342/2 "2021-12-12T15:35:49Z")

</div>

If you refer to the documentation

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

It’ll describe the required authentication:

> ### Authentication
> 
> - User OAuth token
> - Required scope: `channel:read:stream_key`

This means you’ll need to generate a user access token, with the scope `channel:read:stream_key`

Either using:

- OAuth implicit code flow - [Getting OAuth Access Tokens | Twitch Developers](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-implicit-code-flow)
- OAuth authorization code flow - [Getting OAuth Access Tokens | Twitch Developers](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-authorization-code-flow)

Both flows will require a webpage that redirects the user to Twitch to accept or decline the link.

The first (implicit) gives youi a token good for around 60 days  
The second returns a token good for around 4 hours, but comes with a refresh token that you can use to get a new access token.

When you have a token then you can call the Get Stream Key API and fetch the user stream key.

So you’ll need

- to create something that can process the fetching of an access token.
- create something to store the access token (and refresh token)
- use that refresh token as needed to get a new access token  
THEN you’ll be able to write some code to then actually go get the access token.

---

<div class="post-metadata">

**Author:** ![amirhoseyndoran1](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@amirhoseyndoran1](https://staging-discuss.dev.twitch.com/u/amirhoseyndoran1)\
**Post date:** [December 13, 2021, 11:35am UTC](https://staging-discuss.dev.twitch.com/t/get-stream-key-with-python/35342/3 "2021-12-13T11:35:02Z")

</div>

Thanks for the helpful tips 😉

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [January 12, 2022, 11:35am UTC](https://staging-discuss.dev.twitch.com/t/get-stream-key-with-python/35342/4 "2022-01-12T11:35:04Z")

</div>

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