401 Error by this Code?

Go use helix instead:

This snippet should suffice

<?php

 $ch = curl_init('https://api.twitch.tv/helix/streams?user_login=tracepaladinxxl');
 
 curl_setopt_array($ch, array(
    CURLOPT_HTTPHEADER => array(
       'Client-ID: ' . $clientId
    ),
    CURLOPT_RETURNTRANSFER => true
 ));
 
 $response = curl_exec($ch);
 $response = json_decode($repsonse);

  if ($response && $response->data && count($response->data) == 1) {
    echo "Stream is Online";
  } else {
    echo "Stream is Offline";
  }

  echo"</br>";

  var_dump($response, true);