1
$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.

Sourav Das
  • 527
  • 2
  • 5
  • 13
  • This answer help you? [LINK](https://stackoverflow.com/questions/10915108/how-to-add-reply-to-youtubes-video-comment-using-api-with-php) – Simone Rossaini Mar 05 '20 at 09:58
  • `foreach ($ytdata->items->replies as $iteminner)` There's no such thing as `$ytdata->items->replies`. You are already inside a foreach loop of `$ytdata->items`, did you forget this? Do you mean `$item->replies`? – miken32 Mar 05 '20 at 23:42

0 Answers0