How to use Client ID?

I’ve just realised that my stream status does not work anymore and read that I have to include a client ID in the header. How do I do this?

That is my code:

function twitch($channel){
$clientID = "XXX";

$response = json_decode(file_get_contents(''.strtolower($channel).'&client_id=' . $clientID), true);

if ($response['stream'] !== null) {
    $follower = $response['stream'][0]['channel']['followers'];
    $viewer   = $response['stream']['viewers'];
    echo ("Twitch: <span class='live'>Live</span><br>");
    echo ("Viewers: ".$viewer);
} else {
    echo ("Twitch: <span class='offline'>Offline</span>");

It still shows error 400.

Your & should be ?. See URL query format.

If you want to use the header and catch request errors, look into curl.


Problem is with this part '&client_id=' . $clientID)

You need to change the &client_id= to ?client_id=.

EDIT: Lost by a hair :laughing:


cURL example:

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