# How to get my Moderator Id?

**URL:** <https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764>\
**Category:** API\
**Created:** [August 4, 2023, 6:44am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764 "2023-08-04T06:44:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonekit](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bonekit](https://discuss.dev.twitch.com/u/bonekit)\
**Post date:** [August 4, 2023, 6:44am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/1 "2023-08-04T06:44:28Z")

</div>

Hello Folks,

I want to load all chatters from a Twitch Channel, this Channel added me as Moderator.  
I thought my User Id is also my Moderator Id, but this is obviously wrong.

How can i get my mod id?  
Or maybe my function has issues?

```auto
def get_chatters(self, broadcaster_id, moderator_id):
        # Endpoint to get chatters from the Twitch API
        endpoint = self._config_loader.get_endpoint_chatters()

        # Set the headers with the access token
        headers = {
            "Client-ID": self._config_loader.get_client_id(),
            "Authorization": f"Bearer {self._config_loader.get_auth()}",
        }

        # Parameters for the request
        params = {
            "moderator_id": moderator_id,
            "broadcaster_id": broadcaster_id,
        }

        try:
            # Make the API request
            response = requests.get(endpoint, headers=headers, params=params)

            # Check if the request was successful
            if response.status_code == 200:
                data = response.json()
                # Process the data to get chatters from the response
                chatters = data.get("data", [])
                return chatters

            # If the request failed, raise an exception or handle the error accordingly
            response.raise_for_status()

        except requests.exceptions.RequestException as e:
            raise Exception(f"Error while fetching chatters: {e}")

```

Hope someone can help me.

Kind Regards  
Tobias

---

<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:** [August 4, 2023, 8:55am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/2 "2023-08-04T08:55:44Z")

</div>

> [@bonekit](#):
>
> I thought my User Id is also my Moderator Id, but this is obviously wrong.

All “ids” can be gotten from the Get Users Endpoint

Different labels are used on endpoints to describe relationships between the entities involved in a API call

So my

- user\_id is 15185913
- broadcaster\_id is 15185913
- moderator\_id is 15185913

and so on

So as a moderator of cohhcarnage for this call I would use

`https://api.twitch.tv/helix/chat/chatters?broadcaster_id=26610234&moderator_id=15185913`

With a oAuth token of type “user” and the scope `moderator:read:chatters` attached

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

> [@bonekit](#):
>
> ```auto
> except requests.exceptions.RequestException as e:
> raise Exception(f"Error while fetching chatters: {e}")
> 
> ```

What is the error you are getting back? The response body should include a descriptive message to describe the problem

The usual suspect is you generated a client\_credentials/app access token.  
Or your user token is not for you and/or doesn’t have the needed scope

---

<div class="post-metadata">

**Author:** ![bonekit](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bonekit](https://discuss.dev.twitch.com/u/bonekit)\
**Post date:** [August 4, 2023, 9:42am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/3 "2023-08-04T09:42:24Z")

</div>

Hello BarryCarlyon,

Thanks for the fast response.  
I get this message:  
`Exception: Error while fetching chatters: 401 Client Error: Unauthorized for url: https://api.twitch.tv/helix/chat/chatters?moderator_id=79261065&broadcaster_id=495244972`

You wrote:

> The usual suspect is you generated a client\_credentials/app access token.  
> Or your user token is not for you and/or doesn’t have the needed scope

I created an App Token for the Twitch API with Postman, to get the token i used my Client Id and my Secret. Both i got from the Twitch Developer Website.  
The Broadcaster set reading rights for my User, i should have the rights to read his viewers.

---

<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:** [August 4, 2023, 9:44am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/4 "2023-08-04T09:44:59Z")

</div>

> [@bonekit](#):
>
> Exception: Error while fetching chatters: 401 Client Error: Unauthorized for url

This is half the information it’s Just the HTTP Code

Whats the body of the response

> [@bonekit](#):
>
> I created an App Token for the Twitch API with Postman, to get the token i used my Client Id and my Secret. Both i got from the Twitch Developer Website.

App Token’s (aka Client Credentials) cannot be used to call this API you need a USER TOKEN as documented - [Reference | Twitch Developers](https://dev.twitch.tv/docs/api/reference/#get-chatters)

See: [Authentication | Twitch Developers](https://dev.twitch.tv/docs/authentication/#user-access-tokens)

The normal flow used here would be the `code` flow

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#authorization-code-grant-flow)**
>
> Getting OAuth Access Tokens

App Token’s do not represent a user.

> [@bonekit](#):
>
> The Broadcaster set reading rights for my User, i should have the rights to read his viewers.

You do, but it sounds like the generated token does not

---

<div class="post-metadata">

**Author:** ![bonekit](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bonekit](https://discuss.dev.twitch.com/u/bonekit)\
**Post date:** [August 4, 2023, 10:01am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/5 "2023-08-04T10:01:19Z")

</div>

Sorry i am still learning English and the documentation is a little bit difficult for me.  
Message from the Body:

`b'{"error":"Unauthorized","status":401,"message":"Missing User OAUTH Token"}`

What i understand now from the documentation is, i need to create an app token, what i did.  
Now i need to authorize my user and get a token for him too, right?

A few days ago i tried to authorize my user, but the website redirected me to a localhost and there was no code.  
Then i tried it with Postman, but got always error messages back that something was missing.  
I don’t know if’s important for you to help me, my application is written in python and it’s only a console application.

---

<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:** [August 4, 2023, 10:05am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/6 "2023-08-04T10:05:18Z")

</div>

> [@bonekit](#):
>
> What i understand now from the documentation is, i need to create an app token, what i did.  
> Now i need to authorize my user and get a token for him too, right?

No you need a USER token which is what the rror is saying

> [@bonekit](#):
>
> b’{“error”:“Unauthorized”,“status”:401,“message”:“Missing User OAUTH Token”}

> [@bonekit](#):
>
> A few days ago i tried to authorize my user, but the website redirected me to a localhost and there was no code.

oAuth expects a server to be running as your redirect URI (which is defaulted to localhost if you never change it)

The basics of user oAuth is

- User visits your website
- User clicks the link to take them to Twitch
- User accepts (or declines) the link
- If they accept they are redirected to your redirect URI with a `?code`
- Your server exchanges the `?code=` for an access and refresh token

> [@bonekit](#):
>
> I don’t know if’s important for you to help me, my application is written in python and it’s only a console application.

Then you can adapt the oAuth process to run headless.

- Start the app
- App provides a link for the user to copy/paste into a browser
- User is taken to Twitch
- User accepts (or declines) the link
- If they accept they are redirected to your redirect URI with a `?code`
- User copy and pastes the `?code` into your app and the app does the exchange

This is a NodeJS example for “headless” oAuth [https://github.com/BarryCarlyon/twitch\_misc/tree/main/authentication/user\_access\_without\_server](https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/user_access_without_server)

> [@bonekit](#):
>
> I don’t know if’s important for you to help me, my application is written in python and it’s only a console application.

Then you need to figure out a way to obtain a user token to provide the user token to your application so it can operate

---

<div class="post-metadata">

**Author:** ![bonekit](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bonekit](https://discuss.dev.twitch.com/u/bonekit)\
**Post date:** [August 4, 2023, 10:12am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/7 "2023-08-04T10:12:37Z")

</div>

Thank you so much!  
I will try the headless approach and hope it works for me.  
Still much to learn for me 😅

---

<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:** [September 3, 2023, 10:12am UTC](https://discuss.dev.twitch.com/t/how-to-get-my-moderator-id/46764/8 "2023-09-03T10:12:47Z")

</div>

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