How to get my Moderator Id?

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?

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

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

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

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.

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

Whats the body of the response

App Token’s (aka Client Credentials) cannot be used to call this API you need a USER TOKEN as documented - Reference | Twitch Developers

See: Authentication | Twitch Developers

The normal flow used here would be the code flow

App Token’s do not represent a user.

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

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.

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

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

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

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

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

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