Youtube API显示“回复” - PHP [英] Youtube API display "replies" - PHP

查看:149
本文介绍了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='


这篇关于Youtube API显示“回复” - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆