Can't get live chat from stream I do not own

谁都会走 提交于 2020-04-11 12:19:08

问题


There is no way for me to use the YouTubeService_V3 API to read the chat messages from a live stream that does not belong to me.

I want to have a server receive chat messages from a live stream that I do not own. I am only intending to read this data and not write.

I can use YoutubeService/v3/search/list to find live streams if I set EventType to Live and Type to video, and this is pulling up valid live streams when I debug my code.

I can't seem to get the LiveChatID from these streams though in order to use with YouTubeService/v3/LiveChatMessages/List.

Any help with this would be really nice. The chat messages are already public, so I would assume there is no privacy issues.

At the end of the day, I want this server to take a broadcastID such as "pM4IfHZ5qcY" and be able to read in the chat messages, even if it isn't a channel or stream that I own.

I expect to have some way to use YouTubeService_V3 to look up a LiveChatID from a broadcastID, and then be able to use that broadcastID to read the messages from a live stream that I do not own


回答1:


You have to first send a youtube/v3/search request with the channels ID. When you get the video ID that is live, then you have to send a youtube/v3/videos request with the videos ID, and you can then get the liveChatID... Here's an example in Python...

API_KEY = 'XXXXXXXXXXXXXXXXX'
channelID = '<Some Channel ID>'


params = {'part': 'id',
        'key': API_KEY,
        'channelId': channelID,
        'eventType': 'live',
        'type': 'video',
        'order': 'viewCount',
        'fields': 'items(id(videoId))'}

url = 'https://www.googleapis.com/youtube/v3/search'
r = requests.get(url, headers=None, params=params).json()

vID = r.get('items')[0].get('id').get('videoId')



params = {'part': 'liveStreamingDetails,statistics,snippet',
        'key': API_KEY,
        'id': vID,
        'fields': 'items(id,liveStreamingDetails(activeLiveChatId,concurrentViewers,actualStartTime),' + \
                  'snippet(channelId,channelTitle,description,liveBroadcastContent,publishedAt,thumbnails,title),statistics)'}

url = 'https://www.googleapis.com/youtube/v3/videos'
r = requests.get(url, headers=None, params=params).json()


streamData = dict(r.get('items')[0])

chatID = streamData['liveStreamingDetails']['activeLiveChatId']


params = {'part': 'snippet,authorDetails',
        'key': API_KEY,
        'liveChatId': chatID,
        'profileImageSize': 720,
        'maxResults': 500}

url = 'https://www.googleapis.com/youtube/v3/liveChat/messages'
messages = requests.get(url, headers=None, params=params).json()

#messages contains chat messages

I wish there was a better way because just alone, 'search' takes up 100 points of your quota and google only gives you 10,000...




回答2:


Are you looking for a way to read chat messages from a live stream that you don't own?

Even if you know liveChatId, you cannot get chat messages of a live stream that you do not own.

But there's only one way I know.

It's a tricky method, but you can call the chat on the web(url is https://www.youtube.com/live_chat?v=videoId ).

Then, you can get chat messages.



来源:https://stackoverflow.com/questions/57263074/cant-get-live-chat-from-stream-i-do-not-own

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!