The result from the API has 'items' ONLY if it was successful, other wise it has no and your code fails...
You have to check the return value for error code, before processing the data...
A possible error you may have, and the structure of the result in error case:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
Do something like this:
if( isset( $ytdata['error'] ) ) {
}
else {
}
CommentThreads: list | YouTube Data API | Google Developers[
^]