1
votes

So with the code below I am able to get the information shown below e.g. streamTitle.

$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName)), true);

if ($json_array['stream'] != null) {
    $currentGame = $json_array['stream']['channel']['game'];
    $channelTitle = $json_array['stream']['channel']['display_name'];
    $streamTitle = $json_array['stream']['channel']['status'];
    $viewers = $json_array['stream']['viewers'];
}

But what I want to do is to get what comes after self: e.g.(https://api.twitch.tv/kraken/streams/woohaa666) of an API response like the one below which has a specified game and limit, but I'm not sure how to do so. I tried something similar to the code above $channelurlAPI = $json_array['streams']['self'], but it displays nothing.

https://api.twitch.tv/kraken/streams?game=Diablo+III&limit=1

2

2 Answers

0
votes

Im not sure how much this will help you but i was doing work with the twitch API a few months ago I found it very hard but was able to get game searches working and to bring in streams

hope it helps here is the code that i used

//Twitch Streams //Ref: https://github.com/justintv/Twitch-API/blob/master/embedding.md

function getTwitch(title){
$.getJSON("https://api.twitch.tv/kraken/search/streams?q="+title+"&limit=20&type=top&callback=?", function (data) {
    var temp = "";

    $.each(data.streams.slice(0,5), function (index, item) {
        temp = temp + "<a target='frame1' href='http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + item.channel.name + "'><button>"+item.channel.display_name+"</button></a><br />";
    });
    $("#StreamList").html(temp);
});
}

Here is a sample jsfiddle i build using the original api code that u my use as a jumping of point aswell but the code above is the final code I used

http://jsfiddle.net/F4tsM/10/

0
votes

You should try

$json_array['_links']['self']