如何获取 YouTube 直播期间通过“聊天"框输入的评论供稿? [英] How to obtain a feed of comments entered through the 'chat' box during a YouTube live broadcast?

查看:27
本文介绍了如何获取 YouTube 直播期间通过“聊天"框输入的评论供稿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

YouTube API 使用户能够获取评论供稿,例如通过 https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?orderby=published.

The YouTube API enables users to obtain a comments feed, e.g. via https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?orderby=published.

但是,当我尝试使用直播流的视频 ID 执行此操作时,无论提交了多少评论,结果始终为空.直播视频与任何其他视频(或直播流的录制)之间的唯一区别是评论"部分被替换为聊天"框,其评论似乎无法通过 API 获得.

However, when I try to do just that with the video ID of a live stream, the result is always empty, no matter how many comments have been submitted. The only difference between a live video and any other video (or recording of a live stream) is that the 'comments' section is replaced with a 'chat' box, whose comments seem not to be available via the API.

当流停止时,通过聊天框提交的所有评论完全消失"并且无法再访问.但是,在直播存档(即已提供录音)之后提交的所有评论都会显示在评论提要中.

When the stream is stopped, all comments submitted through the chat box 'disappear' entirely and can no longer be accessed. However, all comments submitted after the live broadcast has been archived (i.e. the recording has been made available) show up in the comments feed.

对于实时应用程序,我需要在直播期间访问聊天"评论,以检索用户提交的问题.

For a real-time application I need to access the 'chat' comments while the broadcast is still live, to retrieve user-submitted questions.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

现在可以使用 LiveChatMessages 端点,作为 YouTube 直播 API 的一部分.

It is now possible to return chat messages for your own broadcasts using the LiveChatMessages endpoint as part of the YouTube Live Streaming API.

当创建一个新的liveBroadcast 对象时,一个liveChatId 字符串将作为该liveBroadcastsnippet.将广播的聊天 ID 传递给 LiveChatMessages/list 端点的 liveChatId 参数,以及 idsnippetauthorDetailspart 参数中.

When creating a new liveBroadcast object, a liveChatId String will be returned as part of that liveBroadcast's snippet. Pass your broadcast's chat ID to LiveChatMessages/list endpoint's liveChatId parameter, and id, snippet, and authorDetails into the part parameter.

HTTP GET https://www.googleapis.com/youtube/v3/liveChat/messages?liveChatId={liveChatId}&part=id%2C+snippet%2C+authorDetails&key={YOUR_API_KEY}

这将返回一组 liveChatMessage资源.实际聊天消息包含在 textMessageDetails 字典中,作为 messageText 键的值.

This will return an array of liveChatMessage resources. The actual chat message is contained in the textMessageDetails dictionary as the value for the messageText key.

"textMessageDetails": {
  "messageText": string
}

这篇关于如何获取 YouTube 直播期间通过“聊天"框输入的评论供稿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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