I'm trying to create an overlay for my twitch stream, which display not only the recent follower but a certain amount of them in chronological order.
Here a visual representation:
(Styling is done with HTML/CSS)
I've already managed to get the JSON but I don't know how to echo the names for each ['follows']['user']['display_name']
This is the API: https://api.twitch.tv/kraken/channels/kazutode/follows?limit=5&offset=0&client_id=nht9j8w0u4xazpm1fdc2fmkrqvoici
Here's my code so far (It's not alot, basically nothing xD)
<?php
$clientID = "nht9j8w0u4xazpm1fdc2fmkrqvoici";
$channel = "kazutode";
$limit = 5;
$offset = 0;
$response = json_decode(file_get_contents('https://api.twitch.tv/kraken/channels/'.$channel.'/follows?limit='.$limit.'&offset='.$offset.'&client_id='.$clientID), true);
?>
I know, I know. I should use curl but I don't know how so I stick to json_decode.
Can someone teach me how to get the wanted data out of the ['follows']
array?
You need a foreach loop. Here is some PHP+HTML mixed to give you an idea:
$table = '';
$table .= '<table>';
foreach($response['follows'] as $entry) {
$table .= '<tr>';
$table .= '<td>'.$entry['created_at'].'</td>';
$table .= '<td>'.$entry['user']['display_name'].'</td>';
$table .= '<td><a class="your-custom-class" href="'.$entry['_links']['self'].'">View channel</a></td>';
$table .= '</tr>';
}
$table .= '</table>';
echo $table;