我如何在Python中收到Twitch.tv Webhooks?

问题描述 投票:1回答:1

我正在尝试制作一个简单的Discord Bot,当流媒体上线时发布,但我不确定如何在没有网站的情况下使用Twitch webhooks?是否可以在Python脚本中处理它?

Documentation here

webhookurl = "https://api.twitch.tv/helix/webhooks/hub/"
payload = {"hub.mode":"subscribe",
    "hub.topic":"https://api.twitch.tv/helix/users/streams?user_id=27942990",
    "hub.callback":url,
    "hub.lease_seconds":"0" 
}
header = {"Content-Type":"application/json", "Client-ID": clientid}

req = requests.post(url, headers=header, data = payload)
resp = req.json()

print(resp)

由于我没有网站可以回复,因此不确定要将哪些内容作为回调网址。

我正在使用Python 3.6

旁注:我可以查看一个频道是否有效,但Twitch建议使用webhook来检查流何时上线,我只是想尝试学习这个。

python webhooks discord.py twitch-api
1个回答
0
投票

找到了如何排序(种类)并认为我会在这里回复。

我必须运行一个网络服务器来接受数据,所以这就是我所拥有的。在POST函数中,web.data是响应,表示流是否是活动等

import web

urls = ('/.*', 'hooks')

app = web.application(urls, globals())


class hooks:

    def POST(self):
        data = web.data()
        print("")
        print('DATA RECEIVED:')
        print(data)
        print("")

        return 'OK'

    def GET(self):
        try:
            data = web.input()
            data = data['hub.challenge']
            print("Hub challenge: ", data)
            return data
        except KeyError:
            return web.BadRequest


if __name__ == '__main__':
    app.run()
© www.soinside.com 2019 - 2024. All rights reserved.