Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
256 stars 38 forks source link

TwitchAuthorizationException for listen_bits function #325

Closed JochenFromm closed 3 months ago

JochenFromm commented 3 months ago

I am trying to read chat comments/cheers from a Twitch live steam by using the example code from the Readme (only for bits instead of whispers)...

async def run_example():
    twitch = await Twitch(APP_ID, APP_SECRET)
    auth = UserAuthenticator(twitch, [AuthScope.BITS_READ], force_verify=False)
    token, refresh_token = await auth.authenticate()
    await twitch.set_user_authentication(token, [AuthScope.BITS_READ], refresh_token)
    user = await first(twitch.get_users(logins=[TARGET_CHANNEL]))

    pubsub = PubSub(twitch)
    pubsub.start()

    uuid = await pubsub.listen_bits(user.id, callback)
    input('press ENTER to close...')

    await pubsub.unlisten(uuid)
    pubsub.stop()
    await twitch.close()

...but the "listen_bits" function always returns a TwitchAuthorizationException which indicates that the token is not valid. If I investigate the token then it seems to be valid.

curl -X GET 'https://id.twitch.tv/oauth2/validate -H 'Authorization: OAuth <my_token>
> {"client_id":"<my_client_id>","login":"<my_login>","scopes":["bits:read"],"user_id":"..","expires_in":14850}

What is missing?

Braastos commented 3 months ago

Had the same problem, some time ago. If i remember correctly i read somewhere, that PubSub is being deprecated (could not find a source)... I switched to EventSub Websocket, which provides roughly the same functionality, but slightly different.

Teekeks commented 3 months ago

@Braastos Here is the announcement for the PubSub shutdown in early 2025: https://discuss.dev.twitch.com/t/legacy-pubsub-deprecation-and-shutdown-timeline/58043

JochenFromm commented 3 months ago

Thanks. This means if I want to fetch comments from a Twitch live stream then I need to switch to "EventSub Websocket" (is it possible without costly subscription to the channel ? the example in the file gives an "EventSubSubscriptionError: subscription missing proper authorization") or an IRC chat bot ?

JochenFromm commented 3 months ago

The IRC script from this page works. Thank you for support! Closing this issue then.