How to fetch Twitch clip information using their API and PHP?

Hey everyone! I’m stuck trying to get info about a specific Twitch clip using their API and PHP. I’ve got a code that works fine for other Twitch API stuff, like getting VOD details, but it’s not working for clips. Here’s what I’m doing:

$clipApi = 'https://api.twitch.tv/kraken/clips/streamer/FunnyClipName';
$myClientId = 'abc123xyz';
$curlHandle = curl_init();

curl_setopt_array($curlHandle, array(
    CURLOPT_HTTPHEADER => array(
        'Client-ID: ' . $myClientId
    ),
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => $clipApi
));

$apiResponse = curl_exec($curlHandle);
curl_close($curlHandle);

$decodedJson = json_decode($apiResponse, TRUE);

print_r($decodedJson);

When I run this, I get a 404 error in the response array. But if I change the URL to something like ‘https://api.twitch.tv/kraken/videos/123456789’ for a VOD, it works perfectly. Am I missing something obvious here? Any help would be awesome!

yo, i had the same problem! the other guys are right, u gotta use the helix api now. but heads up, gettin that oauth token can be a pain. i used this php library called ‘league/oauth2-client’ to make it easier. it handles all the token stuff for you. saves a ton of headaches, trust me!

I ran into a similar issue when working with the Twitch API for clips. The problem is that you’re using the old Kraken API, which has been deprecated. For clips, you need to use the new Helix API endpoint.

Here’s how I modified my code to make it work:

$clipApi = 'https://api.twitch.tv/helix/clips?id=YourClipID';
$myClientId = 'abc123xyz';
$myBearerToken = 'your_oauth_token_here';

$curlHandle = curl_init();

curl_setopt_array($curlHandle, array(
    CURLOPT_HTTPHEADER => array(
        'Client-ID: ' . $myClientId,
        'Authorization: Bearer ' . $myBearerToken
    ),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => $clipApi
));

$apiResponse = curl_exec($curlHandle);
curl_close($curlHandle);

$decodedJson = json_decode($apiResponse, TRUE);

print_r($decodedJson);

Make sure to replace ‘YourClipID’ with the actual clip ID and obtain a valid OAuth token. This should resolve the 404 error you’re experiencing. Hope this helps!

I’ve dealt with this exact issue before. The problem lies in the API version you’re using. Twitch has phased out the Kraken API, and you need to switch to the Helix API for clips.

Here’s the key change you need to make:

Replace your clipApi URL with:
https://api.twitch.tv/helix/clips?id=YourClipID

Also, you’ll need to add an OAuth token to your headers. The Helix API requires both Client-ID and Bearer token for authentication.

One more thing - make sure you’re using the correct clip ID. It’s not the clip’s name, but a unique identifier Twitch assigns to each clip.

With these adjustments, your code should work fine. Let me know if you run into any other snags!