Youtube API显示“回复” - PHP

问题描述:

如何在youtube评论中显示回复。



这是我的代码



How can I display the replies in youtube comments.

Here's my code

$videoid = 'UKdZU9Db6fk';
$apikey = 'API KEY';

$json = file_get_contents('https://www.googleapis.com/youtube/v3/commentThreads?maxResults=100&part=snippet%2Creplies&videoId='.$videoid.'&key='.$apikey);
$ytdata = json_decode($json);

foreach ($ytdata->items as $item) {
    echo "Author: ". $item->snippet->topLevelComment->snippet->authorDisplayName;
    echo "Comment: ". $item->snippet->topLevelComment->snippet->textDisplay;

    foreach ($ytdata->items->replies as $iteminner) {
	    echo "Reply: ". $iteminner->comments[0]->textDisplay;
    }
}





我可以显示评论但是对特定评论的回复是我的评论不能做什么,如果有评论有它自己的回复怎么办。



谢谢



我尝试了什么:



我一直在网上搜索,大多数问题都是一样的,他们也遇到同样的问题。



我正在尝试在foreach中添加foreach但结果是



试图获得属性非对象

为foreach提供的参数无效()





这里是xml数据的方式



https://www.googleapis.com/youtube/v3/commentThreads?maxResults=100&part=snippet%2Creplies&videoId=UKdZU9Db6fk&key=AIzaSy CC9AeTosJL21zfVGf8aVPPh9Tz5KTyQGM



谢谢



I can display the comment but the reply into the specific comment is the one that I can't do, also what if there are comments that has it's own replies.

Thanks

What I have tried:

I've been searching on the net and most questions are the same they also have the same problems.

I'm trying to add foreach inside foreach but the result is

"Trying to get property of non-object"
"Invalid argument supplied for foreach() "


Here's how the xml data

https://www.googleapis.com/youtube/v3/commentThreads?maxResults=100&part=snippet%2Creplies&videoId=UKdZU9Db6fk&key=AIzaSyCC9AeTosJL21zfVGf8aVPPh9Tz5KTyQGM

Thanks

videoid = ' UKdZU9Db6fk';
videoid = 'UKdZU9Db6fk';


apikey = ' API KEY';

apikey = 'API KEY';


json = file_get_contents(' https://www.googleapis.com/youtube/v3/commentThreads?maxResults=100&part=snippet%2Creplies&videoId='