diff --git a/standalone_twitch_pubsub copy.py b/standalone_twitch_pubsub copy.py new file mode 100644 index 0000000..224da5c --- /dev/null +++ b/standalone_twitch_pubsub copy.py @@ -0,0 +1,57 @@ +from twitchAPI.pubsub import PubSub +from twitchAPI.twitch import Twitch +from twitchAPI.types import AuthScope, AuthType +from twitchAPI.oauth import UserAuthenticator +from pprint import pprint +from uuid import UUID + +import config +import commands.command_base +import credentials + +credentials_manager = credentials.Credentials_Module() +credentials_manager.load_credentials() +twitchCredential = credentials_manager.find_Twitch_Credential(config.credentialsNickname) + +def callback_channelPoints(self, uuid: UUID, data: dict) -> None: + print("Channel Point Redemption") + print('got callback for UUID ' + str(uuid)) + pprint(data) + +def callback_whisper(uuid: UUID, data: dict) -> None: + print('got callback for UUID ' + str(uuid)) + pprint(data) + +# setting up Authentication and getting your user id +twitch = Twitch(twitchCredential.pubsub_client_id, twitchCredential.pubsub_secret) +twitch.authenticate_app([]) +# you can get your user auth token and user auth refresh token following the example in twitchAPI.oauth + +target_scope = [AuthScope.WHISPERS_READ, AuthScope.CHANNEL_READ_REDEMPTIONS] +auth = UserAuthenticator(twitch, target_scope, force_verify=True) +token, refresh_token = auth.authenticate() +if token is not None: print("found token") +if refresh_token is not None: print("found refresh_token") +#print(token) +#print(refresh_token) +twitch.set_user_authentication(token, target_scope, refresh_token) + + +#twitch.set_user_authentication(twitchCredential.pubsub_AccessToken, target_scope, twitchCredential.pubsub_RefreshToken) +user_id = twitch.get_users(logins=['thecuriousnerd'])['data'][0]['id'] + +# starting up PubSub +pubsub = PubSub(twitch) + +# you can either start listening before or after you started pubsub. +pubsub.ping_frequency = 30 +pubsub.start() + +#uuid1 = pubsub.listen_whispers(user_id, callback_whisper) +uuid2 = pubsub.listen_channel_points(user_id, callback_channelPoints) + +input('press ENTER to close...') +# you do not need to unlisten to topics before stopping but you can listen and unlisten at any moment you want +#pubsub.unlisten(uuid1) +pubsub.unlisten(uuid2) +pubsub.stop() \ No newline at end of file diff --git a/standalone_twitch_pubsub.py b/standalone_twitch_pubsub.py index da2bf5d..1f2a4bd 100644 --- a/standalone_twitch_pubsub.py +++ b/standalone_twitch_pubsub.py @@ -36,8 +36,8 @@ class Twitch_Pubsub(): if token is not None: print("found token") if refresh_token is not None: print("found refresh_token") - #print(token) - #print(refresh_token) + print(token) + print(refresh_token) self.twitch.set_user_authentication(token, self.target_scope, refresh_token) @@ -51,7 +51,7 @@ class Twitch_Pubsub(): def next(self): user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['id'] if user_id is not None: print("found user_id") - #print(user_id) + print(user_id) self.uuid_1 = self.pubsub.listen_whispers(user_id, self.callback_whisper) self.uuid_2 = self.pubsub.listen_channel_points(user_id, self.callback_channelPoints) input('press ENTER to close...')