working token generation
This commit is contained in:
parent
436f4a8193
commit
a5482027f4
@ -3,6 +3,8 @@
|
|||||||
"helix": "Helix Client ID",
|
"helix": "Helix Client ID",
|
||||||
"oauth": "token",
|
"oauth": "token",
|
||||||
"v5_client": "Client ID",
|
"v5_client": "Client ID",
|
||||||
"pubsub client id": "",
|
"pubsub_client_id": "",
|
||||||
"pubsub secret": ""
|
"pubsub_secret": "",
|
||||||
|
"pubsub_AccessToken": "",
|
||||||
|
"pubsub_RefreshToken": ""
|
||||||
}
|
}
|
||||||
@ -14,7 +14,7 @@ class Twitch_Credential():
|
|||||||
# Helix ID = https://dev.twitch.tv/console/apps
|
# Helix ID = https://dev.twitch.tv/console/apps
|
||||||
# Oauth = https://twitchapps.com/tmi/
|
# Oauth = https://twitchapps.com/tmi/
|
||||||
# V5 Client ID = https://twitchtokengenerator.com/
|
# V5 Client ID = https://twitchtokengenerator.com/
|
||||||
def __init__(self, username, helix, oauth, v5_client, pubsub_client_id, pubsub_secret):
|
def __init__(self, username, helix, oauth, v5_client, pubsub_client_id, pubsub_secret, pubsub_AccessToken, pubsub_RefreshToken):
|
||||||
# super().__init__()
|
# super().__init__()
|
||||||
self.username = username
|
self.username = username
|
||||||
self.helix = helix
|
self.helix = helix
|
||||||
@ -22,6 +22,8 @@ class Twitch_Credential():
|
|||||||
self.v5_client = v5_client
|
self.v5_client = v5_client
|
||||||
self.pubsub_client_id = pubsub_client_id
|
self.pubsub_client_id = pubsub_client_id
|
||||||
self.pubsub_secret = pubsub_secret
|
self.pubsub_secret = pubsub_secret
|
||||||
|
self.pubsub_AccessToken = pubsub_AccessToken
|
||||||
|
self.pubsub_RefreshToken = pubsub_RefreshToken
|
||||||
|
|
||||||
|
|
||||||
class Discord_Credential():
|
class Discord_Credential():
|
||||||
|
|||||||
@ -4,5 +4,9 @@
|
|||||||
"path": "."
|
"path": "."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {}
|
"settings": {
|
||||||
|
"cSpell.words": [
|
||||||
|
"unlisten"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -6,6 +6,7 @@ import twitchAPI
|
|||||||
from twitchAPI.pubsub import PubSub
|
from twitchAPI.pubsub import PubSub
|
||||||
from twitchAPI.twitch import Twitch
|
from twitchAPI.twitch import Twitch
|
||||||
from twitchAPI.types import AuthScope
|
from twitchAPI.types import AuthScope
|
||||||
|
from twitchAPI.oauth import UserAuthenticator
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
@ -16,11 +17,20 @@ class Twitch_Pubsub():
|
|||||||
self.credential : credentials.Twitch_Credential()
|
self.credential : credentials.Twitch_Credential()
|
||||||
self.twitch : Twitch()
|
self.twitch : Twitch()
|
||||||
self.pubsub: PubSub()
|
self.pubsub: PubSub()
|
||||||
|
self.target_scope = [AuthScope.CHANNEL_READ_REDEMPTIONS]
|
||||||
|
|
||||||
#Making setup function properly should make all of this run.
|
#Making setup function properly should make all of this run.
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.twitch.authenticate_app([])
|
self.twitch.authenticate_app([])
|
||||||
self.twitch.set_user_authentication('my_user_auth_token', [AuthScope.WHISPERS_READ], 'my_user_auth_refresh_token')
|
|
||||||
|
self.twitch.set_user_authentication(self.credential.pubsub_AccessToken, self.target_scope, self.credential.pubsub_RefreshToken)
|
||||||
|
|
||||||
|
def get_tokens(self):
|
||||||
|
auth = UserAuthenticator(self.twitch, self.target_scope, force_verify=False)
|
||||||
|
token, refresh_token = auth.authenticate()
|
||||||
|
print(token)
|
||||||
|
print(refresh_token)
|
||||||
|
#self.twitch.set_user_authentication(token, self.target_scope, refresh_token)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.pubsub = PubSub(self.twitch)
|
self.pubsub = PubSub(self.twitch)
|
||||||
@ -28,19 +38,25 @@ class Twitch_Pubsub():
|
|||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['id']
|
user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['id']
|
||||||
uuid = self.pubsub.listen_whispers(user_id, self.callback_whisper)
|
#uuid = self.pubsub.listen_whispers(user_id, self.callback_whisper)
|
||||||
|
points = self.pubsub.listen_channel_points(user_id, self.callback_channelPoints)
|
||||||
input('press ENTER to close...')
|
input('press ENTER to close...')
|
||||||
|
|
||||||
self.stop(uuid)
|
self.stop(points)
|
||||||
|
#self.stop(uuid)
|
||||||
|
|
||||||
def stop(self, uuid):
|
def stop(self, thing):
|
||||||
self.pubsub.unlisten(uuid)
|
self.pubsub.unlisten(thing)
|
||||||
self.pubsub.stop()
|
self.pubsub.stop()
|
||||||
|
|
||||||
def callback_whisper(self, uuid: UUID, data: dict) -> None:
|
def callback_whisper(self, uuid: UUID, data: dict) -> None:
|
||||||
print('got callback for UUID ' + str(uuid))
|
print('got callback for UUID ' + str(uuid))
|
||||||
pprint(data)
|
pprint(data)
|
||||||
|
|
||||||
|
def callback_channelPoints(self, uuid: UUID, data: dict) -> None:
|
||||||
|
print("Channel Point Redemption")
|
||||||
|
print('got callback for UUID ' + str(uuid))
|
||||||
|
pprint(data)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
testModule = Twitch_Pubsub()
|
testModule = Twitch_Pubsub()
|
||||||
@ -49,7 +65,7 @@ if __name__ == "__main__":
|
|||||||
credentials_manager.load_credentials()
|
credentials_manager.load_credentials()
|
||||||
testModule.credential = credentials_manager.find_Twitch_Credential(config.credentialsNickname)
|
testModule.credential = credentials_manager.find_Twitch_Credential(config.credentialsNickname)
|
||||||
testModule.twitch = Twitch(testModule.credential.pubsub_client_id, testModule.credential.pubsub_secret)
|
testModule.twitch = Twitch(testModule.credential.pubsub_client_id, testModule.credential.pubsub_secret)
|
||||||
|
pprint(testModule.twitch.get_users(logins=['thecuriousnerd']))
|
||||||
|
|
||||||
testModule.setup()
|
testModule.setup()
|
||||||
testModule.start()
|
testModule.start()
|
||||||
Loading…
Reference in New Issue
Block a user