I never used twitch’s webhooks, but I know about Python. I will tell you some errors or weird parts of your code, and with that, Dist could give you some notes for that things you dont understand about the documentation of twitch’s webhooks, if you have more doubts or problems.
Firts, the most weird part to me:
g = requests.get(url=callback_url,params=f’{callback_url}
hub.mode=subscribe&
hub.topic=https://api.twitch.tv/helix/users/follows?first=1&to_id={apireqs.user_id}
&hub.lease_seconds=864000&hub.challenge=HzSGH_h04Cgl6VbDJm7IyXSNSlrhaLvBi9eft3bw’)
In your code, doesnt appear callback_url
's value, but according to the variable name (and the use as value for payload’s key hub.callback), is a url of your own server. So, if you put that on url
param of requests.get()
, the request was made to yourself, not to twitch.
Furthermore, the params
param (:V) of requests.get()
is bad formated. Assuming that callback_url = "kappa.tv"
, params
's value start with params="kappa.tvhub.mode=subscribe&...etc"
. And requests.get()
then make a request over kappa.tv?kappa.tvhub.mode=subscribe&...etc
(you can see the resulting url with print(g.url)
). Also is bad formated because you have hub.topic url as a GET param (those appears in the request url) being error prone on parse the URL for target server. And this is the second point.
payload dictionary is well formated. But is used on the wrong params. params
param put the key-values appearing in the URL (for GET request), data
put the key-values on the request body (for POST request) BUT … the content-type value for data
is application/x-www-form-urlencoded
, where twitch’s docs is asking for a JSON body, being the content-type application/json
. For that purpose you just need to use json
param instead of data
. So your request code would be r = requests.post(url,headers=header, json=payload)
(I dont know how you are using headers
. if you are using it for the content-type specification, just avoid that and use the json
param).
Finally, a third point about the GET request you are doing. According the docs (the link posted by dist before) , that request just have after
and first
params. Are not the same as the POST request.
Good luck xD