Webhook twitch start

Thank you, I think I’m beginning to understand. I do not know js so I decided to try to do it in php. Took a few steps.

  1. There’s a twitch file.webhook.php that sends the request. In response to the received code 202.
<?php
    $client_id = '***************************';
    $mode = 'subscribe';
    $callback_url = 'http://mysite.com/twitch/twitch.notifications.php';
    $target_user_id = '117191228';

    $lease_days = '10';

    $lease_seconds = $lease_days * 24 * 60 * 60;

    $subscribe_to_event_url = 'https://api.twitch.tv/helix/webhooks/hub';

    $data = array(

    'hub.mode' => $mode,

    'hub.topic' => 'https://api.twitch.tv/helix/users/follows?first=1&from_id='.$target_user_id,

    'hub.callback' => $callback_url,

    'hub.lease_seconds' => $lease_seconds

    );

    $data_string = json_encode($data);

    $ch = curl_init($subscribe_to_event_url);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(

    'Content-Type: application/json',

    'Content-Length:'.strlen($data_string),

    'Client-ID: '.$client_id

    ));

    $result = curl_exec($ch);

    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);

    echo $httpcode."

    ".$result; 
  1. What I did is the twitch file.notifications.php containing script
header("Access-Control-Allow-Headers:*");
ini_set("allow_url_fopen", true);

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
   
   $printString = "";
   
   foreach ($_GET as $key => $value) {
       
       $printString = $printString  . "Key: " . $key . " Val: " . $value . "\n";
   }
   
   file_put_contents("getRequest.txt", $printString);
   
   if (isset($_GET['hub_challenge'])) {
       $challenge = $_GET['hub_challenge'];
       echo $challenge;
       file_put_contents("resget.txt", $challenge);
   }
}

$post = $_POST;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   $payload = "POST received\n";
   file_put_contents("payload.txt", $payload);
}
file_put_contents("respost.txt", $post);`

who accepts answers.

I managed to get

and I don’t know how to respond to that message. Made an echo, but it doesn’t work. All actions, subscriptions, the beginning of the stream, do not work. What am I doing wrong?