getStreamsObjects - PHP error on foreach

So I started using the API :grinning:

Made a small script to query with ‘getStreamsObjects’.

As I am a beginning site none of the streams I queried where online. But the API doesn’t seem to handle an empty very well:

$streamsObject = $this->get_iterated($functionName, $url, $options, $limit, $offset, 'streams', null, $hls, null, $channels, $embedable, $client_id);

Unchecked for empty this goes into:

foreach ($streamsObject as $key => $value)

Giving a PHP error

I fixed this by adding:

if(is_array($streamsObject) && count($streamsObject) > 0)
	{

Last check prohibits empty array into the foreach

This forum is for feedback, questions, and discussion of the official API. There isn’t an official PHP library for Twitch, so I’m guessing you’re using a community-created library. I would suggest giving them the feedback directly. :slight_smile:

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