YouTube 数据 API v3 评论线程差异 [英] YouTube Data API v3 Comment Thread Discrepency

查看:30
本文介绍了YouTube 数据 API v3 评论线程差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用新的 V3 Data API 获取评论列表,但结果喜忧参半.

对于某些视频,您只能获得一部分评论.我在一些视频中注意到了这一点,但对于这个特定情况,我将使用视频 ID = U55NGD9Jm7M

您可以在此处的 WebUI 中找到对该视频的所有评论:https://www.youtube.com/all_comments?v=U55NGD9Jm7M

在发布时,该视频有 5,499 条评论.

API 结果:

查询时https://www.googleapis.com/youtube/v3/commentThreads?part=id,snippet,replies&textFormat=plainText&maxResults=100&videoId=U55NGD9Jm7M&key={YOUR_API_KEY}我只收到大约 317 条评论(包括 Paging,并计算所有回复)(按时间顺序排序).

验证研究:

如果您从下拉列表中选择热门评论",然后向下滚动并一遍又一遍地单击更多",您会收到超过 1,000 条评论(我停在大约 1,000 条)

如果您随后从下拉列表中选择最新优先"并重复该过程(更多...更多...更多),您会发现大约有 317 条评论,然后您无法再显示更多评论.

我觉得 UI 中存在差异很奇怪,但感谢 API 与部分 UI 对齐.有没有其他人注意到这一点?有没有办法获取所有 5,499 条评论的全文?

谢谢!

杰森

跟进 1

作为后续,我能够使用 View->Source(线程 ID z12wzfzhtybgz13kj22ocvsz2unrtn1qj04)隔离一条评论,并在此处的 API 中从该评论中获取所有信息:https://www.google/Threadsv.com?part=id%2Csnippet%2Creplies&id=z12wzfzhtybgz13kj22ocvsz2unrtn1qj04&maxResults=100&key={YOUR_API_KEY})

它甚至提到了与评论相关联的正确 VideoID.但是,当您通过Video查询时,不会返回此评论ID.

跟进 2我刷新了所有评论的 Web UI,返回的评论列表明显不同

解决方案

commentsThread.list 调用最多只能返回 100 个结果(请参阅 maxResultsa href="https://developers.google.com/youtube/v3/docs/commentThreads/list#parameters" rel="nofollow">文档).如果您想获得更多评论线程,则必须将您从初始调用中获得的 nextPageToken 传递到后续 API 调用中.

例如:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=U55NGD9Jm7M&maxResults=100&key=API_KEY

给你 100 个评论线程,nextPageTokenCg0Qk9fa7fHgxgIgACgBEhQIARCY49LZ5eDGAhi4rNGIrZrGAhgCIGM.如果您在新的 API 调用中包含该令牌,如下所示:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=Dlj6SUg9B04&&maxResults=100&nextPageToken=Cg0Qk9fa7fHgxgIgACgBEhQIARCY49LZ5rGiD

您会得到一组完全不同的评论线程.您可以通过在两个 API 调用中指定 order=time 来仔细检查这一点.您将看到两个调用的最早评论线程不同,并且您不会在另一个调用的结果中找到任何一个的评论线程 ID.要获得更多评论线程,您可以从较新调用的结果中获取 nextPageToken 并再次执行相同的操作(直到调用没有给您另一个 nextPageToken,这意味着您'在最后一页,没有更多评论线程要返回).

I have been trying to get a list of comments out using the new V3 Data API with mixed results.

For some videos, you only get a subset of comments out. I have noticed this on a few videos, but for this specific case I will use video ID = U55NGD9Jm7M

You can find all the comments on this video in the WebUI here: https://www.youtube.com/all_comments?v=U55NGD9Jm7M

At the time of posting, there were 5,499 comments on this video.

API Results:

When querying https://www.googleapis.com/youtube/v3/commentThreads?part=id,snippet,replies&textFormat=plainText&maxResults=100&videoId=U55NGD9Jm7M&key={YOUR_API_KEY} I am only getting about 317 comments (including Paging, and counting all replies) (sorted chronologically).

Verification Research:

If you select "Top Comments" from the drop down and then scroll down and click "More" over and over again, you get over 1,000 comments (I stopped at about 1,000)

If you then select "Newest First" from the dropdown and repeat the process (more ... more ... more) you will find that there are about 317 comments before you are unable to show any more comments.

I find it quite odd that there is a discrepancy in the UI, but thankful that the API lines up with part of the UI. Has anyone else noticed this? Is there a way to get the full text of all 5,499 comments?

Thanks!

Jason

Follow-up 1

As a follow-up, I was able to isolate one comment using View->Source (Thread ID z12wzfzhtybgz13kj22ocvsz2unrtn1qj04) and fetch all the information from this comment in the API here: https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet%2Creplies&id=z12wzfzhtybgz13kj22ocvsz2unrtn1qj04&maxResults=100&key={YOUR_API_KEY})

It even mentions the correct VideoID that the comment is associated with. However, when you query by Video, this comment ID is not returned.

Follow-up 2 I refresh the Web UI of the All Comments, and there was a significantly different list of comments that are being returned

解决方案

The commentsThread.list call can only return a maximum of 100 results (see maxResults in the documentation). If you wanted to get more comment threads, you'd have to pass in the nextPageToken you get from your initial call into a subsequent API call.

For example:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=U55NGD9Jm7M&maxResults=100&key=API_KEY

gives you 100 comment threads, and the nextPageToken is Cg0Qk9fa7fHgxgIgACgBEhQIARCY49LZ5eDGAhi4rNGIrZrGAhgCIGM. If you include that token in a new API call, like so:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=Dlj6SUg9B04&&maxResults=100&nextPageToken=Cg0Qk9fa7fHgxgIgACgBEhQIARCY49LZ5eDGAhi4rNGIrZrGAhgCIGM&key=API_KEY

You get a completely different set of comment threads. You can double check this by specifying order=time in both API calls. You'll see that the earliest comment threads for both calls are different, and you won't find the comment Thread ID for either in the other call's results. To get even more comment threads, you take the nextPageToken from the newer call's results and do the same thing again (until the call doesn't give you another nextPageToken, meaning you're on the last page, and there are no more comment threads to return).

这篇关于YouTube 数据 API v3 评论线程差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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