如何解决订阅stream_changed webhook python twitch API 总是失败
我正在尝试订阅 stream_changed webhook,并在用户使用 python Twitch API 在 twitch 上直播时收到通知。 我已经设置好了一切,但是当我尝试订阅 webhook 时,我总是将订阅状态设置为 false,这意味着我无法订阅 webhook。 这是我正在使用的代码。
from twitchAPI.twitch import Twitch
from twitchAPI.types import AuthScope
from twitchAPI.webhook import TwitchWebHook
from pprint import pprint
import json
import ssl
config = json.load(open('config.json','r'))
IP_ADDRESS = config.get('PUBLIC_ADDR')
PORT = config.get('PUBLIC_PORT')
APP_ID = config.get('APP_ID')
APP_SECRET = config.get('APP_SECRET')
PUBLIC_ADDR = f'https://{IP_ADDRESS}:{PORT}'
print(f'Public address : {PUBLIC_ADDR}')
TOKEN = config.get("TOKEN")
REFRESH_TOKEN = config.get("REFRESH_TOKEN")
def callback_stream_changed(uuid,data):
print('Callback Stream changed for UUID ' + str(uuid))
pprint(data)
# basic twitch API authentication,this will yield a app token but not a user token
auth_scope = [
AuthScope.BITS_READ,AuthScope.USER_EDIT,AuthScope.WHISPERS_READ,AuthScope.CHANNEL_READ_SUBSCRIPTIONS,AuthScope.CHANNEL_READ_STREAM_KEY,AuthScope.ANALYTICS_READ_EXTENSION,AuthScope.ANALYTICS_READ_GAMES,AuthScope.CHANNEL_EDIT_COMMERCIAL,AuthScope.CHANNEL_READ_HYPE_TRAIN,AuthScope.CHANNEL_MANAGE_BROADCAST,AuthScope.CHANNEL_READ_REDEMPTIONS,AuthScope.CLIPS_EDIT,AuthScope.USER_EDIT_BROADCAST,AuthScope.USER_READ_BROADCAST,AuthScope.USER_READ_EMAIL,AuthScope.USER_EDIT_FOLLOWS,AuthScope.CHANNEL_MODERATE,AuthScope.CHAT_EDIT,AuthScope.CHAT_READ,AuthScope.WHISPERS_EDIT,AuthScope.MODERATION_READ,AuthScope.CHANNEL_SUBSCRIPTIONS
]
twitch = Twitch(APP_ID,APP_SECRET)
twitch.authenticate_app(auth_scope)
twitch.set_user_authentication(
TOKEN,auth_scope,REFRESH_TOKEN)
sslContext = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS)
hook = TwitchWebHook(PUBLIC_ADDR,APP_ID,PORT,ssl_context=sslContext)
hook.authenticate(twitch)
hook.start()
user_info = twitch.get_users()
user_id = user_info['data'][0]['id']
print(f'User ID : {user_id}')
success,uuid_stream = hook.subscribe_stream_changed(
user_id,callback_stream_changed)
print(f'Was subscription successfull?: {success}')
input('[+] Press enter to stop...')
success = hook.unsubscribe(uuid_stream)
print(f'was unsubscription successfull?: {success}')
# since hook.unsubscribe_on_stop is true,we dont need to unsubscribe manually,so lets just stop
hook.stop()
这里成功的值为 False。 如果我做错了什么或遗漏了什么,有人可以指导我吗? 顺便说一句,这是我第一次使用 twitch API。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。