I’m trying to fetch featured streamers from Twitch using their API but keep getting an error message about an illegal string offset for ‘channel’. My goal is to display the streamer names and their current viewer counts.
Here’s my current code:
<?php
$response = file_get_contents('https://api.twitch.tv/kraken/streams/featured');
$decoded_data = json_decode($response, TRUE);
foreach ($decoded_data as $item) {
foreach ($item as $stream_info) {
echo $stream_info['channel']['display_name'] . "<br/>";
echo $stream_info['channel']['viewers'] . "";
}
}
?>
The error happens when I try to access the channel data. What am I doing wrong with the array structure?