Error 401: "Unauthorized" "invalid oauth token" when requesting user information

Right lets start from the beginning.

You have created a clientID via

Then you have fetched and obtained a valid oAuth via

bear in mind that oAuth’s generated will also expired after a time

Then using the oAuth Token generated the php code:

<?php
   
    $ch = curl_init('https://api.twitch.tv/kraken/user');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: OAuth ' . $the_oauth,
        'Accept: application/vnd.twitchtv.v5+json'
    ));
    
    $result = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($result);

    print_r($result);

Will work