I don't understand the new API

Hi everyone,

I have a simple script that works since 2017 in PHP : show the streams of a particular game and language (french).
Since a few days this one does not work anymore.

The request was the following (it worked well) :

https://api.twitch.tv/kraken/streams/?game=MYGAME&language=fr&client_id=XXXX

I replaced kraken with helix.

But I have a 401 error that appears: “Must provide a valid Client-ID or OAuth token”.

I did not change anything in my twitch developers panel. My cliend id is still valid.

What is the problem ?

Thanks for you help.

You must change the following

  1. Send game_id instead of game

Get the game ID for your game here:

  1. Send the client ID as a header not as a query string

In PHP this is via setting a Header as a curl option

https://www.php.net/curl_setopt

CURLOPT_HTTPHEADER An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100')

So, (incomplete code snippet):

$ch = curl_init('https://api.twitch.tv/helix/streams?game_id=123');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Client-ID: YourClientID'));

For example

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