Reputation: 101
I'm trying to make a simple Discord Bot that posts when a streamer goes live but I'm not sure how to use the Twitch webhooks without having a website? Is it possible to handle it all in a Python script?
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)
Not sure what to put as the callback URL since I don't have a website to respond.
I'm using Python 3.6
Side note: I can find out if a channel is live but Twitch recommends the webhooks for checking when a stream goes live and I just want to try learn this.
Upvotes: 1
Views: 2711
Reputation: 101
Found out how to sort it(kind of) and thought I'd reply here.
I have to run a webserver to accept the data so this is what I have. In the POST function the web.data is the response which says if stream is live/not etc
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()
Upvotes: 1