Closed yankiva closed 4 years ago
@yankiva Can provide a code snippet of the method you are calling and the parameter to use in order to reproduce this? thanks
We got a list of Youtube users/channels to retrieve stats. One of our channels were disabled, so we got this error and it breaks all further actions. It could be useful to have some log record here instead error.
In Youtube.php line 601:
[ErrorException]
Undefined property: stdClass::$items
Exception trace: at /var/www/project/vendor/alaouy/youtube/src/Youtube.php:601 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at /var/www/project/vendor/alaouy/youtube/src/Youtube.php:601 Alaouy\Youtube\Youtube->decodeSingle() at /var/www/project/vendor/alaouy/youtube/src/Youtube.php:346 Alaouy\Youtube\Youtube->getChannelByName() at /var/www/project/app/Console/Commands/loadSocialData.php:157
@yankiva The method getChannelByName and all other methods interacting with the youtube api will throw an exception if the api response is not what you would expect, so you can surround your code with a try catch block and handle the exceptions there.
Somethimes $items not present in the response class stdClass#970 (3) { public $kind => string(27) "youtube#channelListResponse" public $etag => string(27) "XXX" public $pageInfo => class stdClass#971 (2) { public $totalResults => int(0) public $resultsPerPage => int(5) } } So, script crashes with error: In Youtube.php line 599:
Undefined property: stdClass::$items
In public function decodeSingle(&$apiData).