Problem using twitch API

I am using a little PHP script to get my channels previous broadcasts. When I run this script locally , everything works fine. When I upload it to my webspace, I get nothing. no errors, no warnings. no response at all.

here is the api I am calling: https://api.twitch.tv/kraken/channels/{{{MYCHANNELNAME}}}/videos?broadcasts=true

Ive replaced my channel name with {{MYCHANNELNAME}}}.

Can you post code? That will help with narrowing down the problem. :slight_smile:

function twitchAPIRequest($url)
{
        $output = file_get_contents($url);
        return $output;
}



function decodeJ($json)
{
    $decodedJson = json_decode($json);
	$list = "<ul>";
	for($i = 0; $i < $decodedJson->_total-1; $i++)
	{
			$videos = $decodedJson->videos[$i]->_id;
			$preview = $decodedJson->videos[$i]->preview;
			$list.="<li><a href='screen.php?vid={$videos}'><img src={$preview} width='180' height='112'></a></li>" ;
	}
	$list.="</ul>";
	return $list;
}


$json = twitchAPIRequest("https://api.twitch.tv/kraken/channels/MYCHANNEL/videos?broadcasts=true");

The decodeJ function is called from html . I get no response from the api call. It works locally fine

There is a good possibility file_get_contents is failing. You should really be using cURL so you can also send the Client-ID, which will be a hard requirement in about a month. Check out this thread for more info about using cURL: Script doesnt work

Thanks for your replies.

Can I run that function without the clientId? or will the clientId of 000000000 be sufficient?

Not sure how to et one just yet (sorry only just started having a look into this api) .

For now, yes, you can run the function without the Client-ID. To get a Client-ID, just use the Register your application button at the bottom of this page.

Thanks for your help Dallas. Its much appreciated . Worked online but not locally. I can see ive a lot of learning ahead.

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