# Problems with the OAuth token

**URL:** <https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590>\
**Category:** API\
**Created:** [April 27, 2024, 5:43pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590 "2024-04-27T17:43:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shhenu](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shhenu](https://discuss.dev.twitch.com/u/shhenu)\
**Post date:** [April 27, 2024, 5:43pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/1 "2024-04-27T17:43:06Z")

</div>

I’m currently working on what seemed to me a simple project using the Twitch API in a Python program on my desktop. All I want the program to do is to capture every message written in a Twitch channel’s chat and for each new message, add 1 second to a timer made in HTML. So, I’ve obtained TWITCH\_CLIENT\_ID, TWITCH\_TOKEN, TWITCH\_CLIENT\_SECRET. However, every time I try to call anything, I get a 401 Client Error: Unauthorized for URL. And, as I understood and was explained on the internet, I need to check and modify the format and permission of the Auth token. I assume the problem is probably with this? How to solve this problem in a Python program? Thank you!

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 27, 2024, 5:45pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/2 "2024-04-27T17:45:21Z")

</div>

For reading chat are you trying to connect to Chat over IRC or over EventSub?

When you get a 401 what URL or API request are you attempting?

---

<div class="post-metadata">

**Author:** ![shhenu](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shhenu](https://discuss.dev.twitch.com/u/shhenu)\
**Post date:** [April 27, 2024, 5:53pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/3 "2024-04-27T17:53:10Z")

</div>

Sorry, I’m a complete novice in programming, and I’ve been helped to implement this artificial intelligence idea. If I send you the code that triggers this error, would it help you understand the situation?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 27, 2024, 5:55pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/4 "2024-04-27T17:55:41Z")

</div>

That would be useful yes.

---

<div class="post-metadata">

**Author:** ![shhenu](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shhenu](https://discuss.dev.twitch.com/u/shhenu)\
**Post date:** [April 27, 2024, 5:57pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/5 "2024-04-27T17:57:55Z")

</div>

```auto
import twitchio

# Your credentials
TWITCH_CLIENT_ID = ""
TWITCH_CLIENT_SECRET = ""
TWITCH_NICKNAME = ""
TWITCH_TOKEN = "oauth:"
TWITCH_CHANNEL = ""

async def check_connection():
    try:
        # Creating a Twitch client
        bot = twitchio.Client(
            client_id=TWITCH_CLIENT_ID,
            client_secret=TWITCH_CLIENT_SECRET,
            token=TWITCH_TOKEN,
            nick=TWITCH_NICKNAME,
            initial_channels=[TWITCH_CHANNEL]
        )

        # Connecting to Twitch chat
        await bot.start()
        print("Successfully connected to Twitch chat!")

    except twitchio.exceptions.AuthenticationError as e:
        print("Authentication error:", e)
    except Exception as e:
        print("An error occurred while connecting:", e)
    finally:
        # Closing the connection
        await bot.close()

# Running the connection check script
if __name__ == " __main__":
    import asyncio
    asyncio.run(check_connection())

```

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [April 27, 2024, 5:59pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/6 "2024-04-27T17:59:06Z")

</div>

Theres nothing here that would surface the error you have reported.

Since you are using twitchio you might fare better in the twitchio focussed rooms on the Libraries Discord:

> **[Join the Twitch API Discord Server!](https://discord.com/invite/8NXaEyV)**
>
> A server about anything Twitch API related! | 6102 members

---

<div class="post-metadata">

**Author:** ![shhenu](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shhenu](https://discuss.dev.twitch.com/u/shhenu)\
**Post date:** [April 27, 2024, 6:00pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/7 "2024-04-27T18:00:29Z")

</div>

Understood, thank you.

---

<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:** [May 27, 2024, 6:00pm UTC](https://discuss.dev.twitch.com/t/problems-with-the-oauth-token/58590/8 "2024-05-27T18:00:48Z")

</div>

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