$json = file_get_contents('https://www.googleapis.com/youtube/v3/commentThreads?maxResults=100&part=snippet%2Creplies&videoId=CrFY7er7q5M&key=AIzaSyCgtv2Pjl5PWdwVIJKspMZpXYrrQJ0hnl4&maxResults=100');
$ytdata = json_decode($json);
foreach ($ytdata->items as $item) {
echo "Author: ". $item->snippet->topLevelComment->snippet->authorDisplayName;
echo "<br>";
echo "Comment: ". $item->snippet->topLevelComment->snippet->textDisplay;
echo "<br><br>";
foreach ($ytdata->items->replies as $iteminner) {
echo "Reply: ". $iteminner->comments[0]->textDisplay;
}
}
I can display the comment but the reply into the specific comment is the one that I can't do. It is showing error like this,
Notice: Trying to get property 'replies' of non-object on line 15
Warning: Invalid argument supplied for foreach() on line 15
Can anyone help me to fix this issue? Thanks.