Python POST Request Gives Unknown Result

- 1 answer

So I'm really out of my element with RESTful stuff. I'm trying to make a thing on that subscribes to an action/webhook(?) on so that if someone goes live, it knows.

I want to use this webhook here:

I made a Flask server in

app = Flask(__name__)

@app.route('/', methods=['POST'])
def result():
    return 'Received'

and the POST I make is over here in

import requests
r ="", headers={'Client-ID': client_id}, data={"hub.callback": "","hub.mode":"subscribe",'hub.topic':""})

Running my code shows nothing on the server, not even Received so I guess I'm doing something wrong.

if I do a GET, on request = requests.get('', headers={'Client-ID': client_id})

the result is b ' '

and I have no idea what that means

in, putting a print(r) returns <Response [202]> but I think I want a [200]

I assume my server needs to be reachable by Twitch to see it but I'm not sure.

Any help is appreciated!



Final EDIT... I have created a proof of concept

You're POSTing "hub.callback": "". That URL is only accessible on your machine.

This is supposed to be a URL which is accessible from the Twitch infrastructure. If you can't register a domain, then you could use something like ngrok to get a valid URI which routes back to your Flask development server for testing.

Once you have sent the POST request, you can get the webhook subscriptions to confirm the post request worked. This is also possible using curl, with the commands included to the right of this documentation.

Assuming you see valid subscriptions there, then the endpoint you provide as hub.callback should receive a hit from Twitch...

when a stream changes; e.g., stream goes online or offline, the stream title changes, or the game changes.

Within the route you'd then do some logic to deal with the result of that request.

Update re comments

You may wish to try updating hub.lease_seconds: (here)

Number of seconds until the subscription expires. Default: 0. Maximum: 864000.

The default (0) allows you to test the subscription-creation workflow without creating any subscriptions (since they expire immediately). After testing, to actually create subscriptions, you must specify a larger value.

This belongs in the dictionary passed as the data argument to in