Got no requests of twitch webhook after subscription

Hello,

I would like to use the webhook for to show if a user is live.

I executed this code (replaced own data):
$data = array(
‘hub.callback’ => ‘https://myurl/twitch/webhook_redirect.php’,
‘hub.mode’ => ‘subscribe’,
‘hub.topic’ => ‘https://api.twitch.tv/helix/streams?user_id=147837668’,
‘hub.lease_seconds’ => 864000
);
$dataString = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.twitch.tv/helix/webhooks/hub");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	'Client-ID: myclientid',
	'Content-Type: application/json',
	'Content-Length: ' . strlen($dataString)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);
$info = curl_getinfo($ch);

curl_close ($ch);

print_r($server_output);
print_r($info);

I got the response code 202 and my webhook_redirect.php was requested and I got the hub_challenge “C5JUIAPXHt2OogUeP8oXv8uXhoZ_BCq5vj9XUPaN”.
But if I go live with the user, my script got no request of twitch. This is my webhook_redirect.php:
<?php
file_put_contents(“get.txt”, json_encode($_GET)."\n", FILE_APPEND);
file_put_contents(“post.txt”, json_encode($_POST)."\n", FILE_APPEND);
file_put_contents(“request.txt”, json_encode($_REQUEST)."\n", FILE_APPEND);
$request_body = file_get_contents(‘php://input’);
file_put_contents(“json.txt”, $request_body."\n", FILE_APPEND);

In the files are no new entries for requests from twitch.
How can I fix this or is it a twitch bug?

kind regards
Hanashi

Did you see the incoming post request from Twitch in your web server access logs?

Did you see an error in your incoming server error logs?

Did you reply to the incoming hub_challenge with the hub_challenge?

<?php

    if ($_GET['hub_challenge']) {
        echo $_GET['hub_challenge'];
        exit;
    }
1 Like

I added now the script snippet from you to webhook_redirect.php und resubscribed (unsubsribe and subscribe) to the webhook, but I have the same problem.

There is no entry in my error.log or acces.log of my webserver for a request from twitch after subscribing. There is only a entry of the subscription request.

Edit: It’s magical. Now it works. Thanks for help.

On a side note:

There is on average a 3 minute delay from video start for the up webhook and a 6 minute delay from video end for the down

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.