PetterKraabol / Twitch-Python

Object-oriented Twitch API for Python developers
https://pypi.org/project/twitch-python
MIT License
214 stars 37 forks source link

Helix responds with 401 #35

Closed Schrotty closed 3 years ago

Schrotty commented 3 years ago

Hello there, I tried to fetch the moderators of a channel but got a 401.

self.twitch_helix = twitch.Helix(client_id=f'{os.getenv("TWITCH.CLIENTID")}', use_cache=True, client_secret=f'{os.getenv("TWITCH.SECRET")}')

identifier: str = self.twitch_helix.user("schrottler").id
mods = self.twitch_helix.api.get("moderation/moderators", {"broadcaster_id": identifier}).get()

Both ClientID and ClientSecret are set. Any idea? Or is this type of request not supported?

MPeti1 commented 3 years ago

I'm hitting the same problem, could you tell what was your solution?

Schrotty commented 3 years ago

Oh, sorry, no solution. I used another library in the end.

MPeti1 commented 3 years ago

oh, thank you. it's bad news, because afaik other libraries don't have support for the stream chat :/

MPeti1 commented 3 years ago

I think I found it out. writing here so others may find this.

It seems the Helix class does not obtain an oauth token for itself. Twitch Chat Downloader obtains the oauth token by itself, using this snippet:

oauth_token = requests.post(f"https://id.twitch.tv/oauth2/token"
                                f"?client_id={client_id}"
                                f"&client_secret={client_secret}"
                                f"&grant_type=client_credentials").json()['access_token']

and then uses this contructor:

helix = twitch.Helix(client_id=client_id, bearer_token=oauth_token, use_cache=True)
MPeti1 commented 3 years ago

but well, in the end I get the same random errors and slowness as I had with TCD :/