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}")
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.
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.