Kraken/clips/top HTTP request failed, + basic question

I want to get the “trending” clips from a channel, and it looks like New Twitch Api can only order them by view count.

So I had to use kraken and it looks like this :

public function getTopClips($channel_name, $period = 'week', $max = 5, $trending = true)
    $url = ''.$channel_name.'&limit='.$max.'&period='.$period.'&trending='.$trending;

    $opts = [
        "http" => [
            "method" => "GET",
            "header" => "Client-ID: ".$this->client_id .
                        "Accept: application/vnd.twitchtv.v5+json"

    $context = stream_context_create($opts);
    $json_result = file_get_contents($url, false, $context);
    $result = json_decode($json_result);

    return $result;

And I’m getting this error : Warning: file_get_contents( failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found

Everything works fine when I use Helix, so I guess there is something I don’t understand about kraken.

Also, is it possible to get clips from multiple channels with one request ?

Use cURL and specify headers.

With no headers it defaults to v3 and theres no clips endpoints on v3.

Also on most hosts file_get_contents over HTTP is blocked as it’s unsafe.

It looks like it should work with your code, but just don’t use file_get_contents as a rule

However the correct opts is:

$opts = [
        "http" => [
            "method" => "GET",
            "header" => "Client-ID: ".$this->client_id . "\r\n"
                        "Accept: application/vnd.twitchtv.v5+json\r\n"
1 Like

Thank you for your help !

That was definitely a noobDev question, and I didn’t know about file_get_contents being unsafe, I should learn more about that.

Have a good day, Sir !

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