How to obtain a feed of comments entered through the 'chat' box during a YouTube live broadcast?
Solution 1
It is now possible to return chat messages for your own broadcasts using the LiveChatMessages
endpoint as part of the YouTube Live Streaming API.
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}
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
}
Solution 2
Ibrahim Ulukaya, a member of Google's Developer Relations team focusing on the YouTube API, stated the following on a similar quesiton (How to get chat content of Youtube live event in Java):
The API doesn't have connection to live chat at this moment. We are hoping to get that content incorporated into API soon.
via https://stackoverflow.com/a/26427743/1085891
Related videos on Youtube
Marcus Wernicke
Updated on July 09, 2022Comments
-
Marcus Wernicke almost 2 years
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
.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?
-
DarkPh03n1X about 8 yearsCould you Please Give a C# method for this??
-
JAL about 8 years@DarkPh03n1X what are you having trouble with? The web request? Maybe you should ask a new question.
-
Matt Fletcher over 7 yearsWhy Are You Writing In Sentence Case Like Jaden Smith?
-
Matt Fletcher over 7 yearsBut seriously, this is really not the best method of doing this. It's slow, it's very likely to break when they change any markup, it won't get all comments, only those visible, etc.
-
DarkPh03n1X over 7 yearsI actually did this using google's api. when google's api supported it a couple a months ago.As For Your First Question I Have No Idea What You Are Talking About.
-
Mikhail M. over 7 yearsWhy aren't all broadcasts available? Threre are no private broadcasts, right?
-
ynn almost 4 yearsFive years have past since the answer was posted. The situation changed? Do we still have to stick to Selenium to fetch chats of someone else's live stream?