![]() ![]() # unsubscribe from all old events that might still be there # this will ensure we have a clean slate await event_sub. # basic setup, will run on port 8080 and a reverse proxy takes care of the https and certificate event_sub = EventSub( EVENTSUB_URL, APP_ID, 8080, twitch) # since we do not need the resulting token after this authentication, we just discard the result we get from authenticate() # Please read up the UserAuthenticator documentation to get a full view of how this process works auth = UserAuthenticator( twitch, TARGET_SCOPES) # the user has to authenticate once using the bot with our intended scope. # create the api instance and get the ID of the target user twitch = await Twitch( APP_ID, APP_SECRET) # our event happend, lets do things with the data we got! print( data) types import AuthScope import asyncio TARGET_USERNAME = 'target_username_here' EVENTSUB_URL = '' APP_ID = 'your_app_id' APP_SECRET = 'your_app_secret' TARGET_SCOPES = oauth import UserAuthenticator from twitchAPI. The EventSub client runs in its own thread, calling the given callback function whenever an event happens.Ī more detailed documentation, including the setup requirements can be found here on readthedocs Short code example:įrom twitchAPI. unlisten( uuid)ĮventSub lets you listen for events that happen on Twitch. # you do not need to unlisten to topics before stopping but you can listen and unlisten at any moment you want await pubsub. # you can either start listening before or after you started pubsub. # starting up PubSub pubsub = PubSub( twitch) set_user_authentication( token,, refresh_token) # you can get your user auth token and user auth refresh token following the example in twitchAPI.oauth await twitch. # setting up Authentication and getting your user id twitch = await Twitch( APP_ID, APP_SECRET)Īuth = UserAuthenticator( twitch,, force_verify = False) Print( 'got callback for UUID ' + str( uuid)) TARGET_CHANNEL = 'teekeks42' async def callback_whisper( uuid: UUID, data: dict) -> None: oauth import UserAuthenticator import asyncio from pprint import pprint from uuid import UUID APP_ID = 'my_app_id' APP_SECRET = 'my_app_secret' USER_SCOPE = Please read the docs for more details and examples on how to set and use Authentication! App AuthenticationĪpp authentication is super simple, just do the following:įrom twitchAPI. It's always good to get at least App authentication even for calls where you don't need it since the rate limits are way better for authenticated calls. ![]() Which one you need (or if one at all) depends on what calls you want to use. The Twitch API knows 2 different authentications. # print the ID of your user or do whatever else you want with it print( user. # call the API for the data of your twitch user # this returns a async generator that can be used to iterate over all results # but we are just interested in the first result # using the first helper makes this easy. # initialize the twitch instance, this will by default also create a app authentication for you twitch = await Twitch( 'app_id', 'app_secret') helper import first import asyncio async def twitch_example(): ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |