I am fetching a json string
$url = 'https://api.twitch.tv/kraken/channels/rootkitztv/follows';
and want to fetch the users who have a profile pic. Those don't it returns as 'null'.
Here is my script
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$followers_list = curl_exec($ch);
$followers_result = json_decode($followers_list, true);
foreach ($followers_result as $data)
{
foreach ($data as $datas) {
echo ("<img src=\"".$datas['user']['logo']."\"/>");
}
}
When I run it I get all the images displaying properly but also the following errors...
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/twitch/test.php on line 27
Warning: Illegal string offset 'user' in /Library/WebServer/Documents/twitch/test.php on line 30
Warning: Illegal string offset 'logo' in /Library/WebServer/Documents/twitch/test.php on line 30
Warning: Illegal string offset 'user' in /Library/WebServer/Documents/twitch/test.php on line 30
Warning: Illegal string offset 'logo' in /Library/WebServer/Documents/twitch/test.php on line 30
and 2 images come through as <img src="h"/>
in the page source.
Im lost as where this happens but also wondering if this is related to some logos being null. Not sure why I am getting these errors.