无法从我不拥有的信息流中获得实时聊天 [英] Can't get live chat from stream I do not own
问题描述
我无法使用 YouTubeService_V3 API 从不属于我的实时流中读取聊天消息.
我希望服务器从我不拥有的实时流中接收聊天消息.我只打算读取此数据,而不要写入.
如果我将EventType设置为Live,将Type设置为video,则可以使用 YoutubeService/v3/search/list 查找实时流,这在调试代码时会提取有效的实时流./p>
尽管为了与 YouTubeService/v3/LiveChatMessages/List 一起使用,我似乎无法从这些流中获取LiveChatID.
任何与此有关的帮助都将非常好.聊天消息已经公开,因此我认为没有隐私问题.
在一天结束时,我希望该服务器采用 broadcastID ,例如"pM4IfHZ5qcY",并能够读取聊天消息,即使它不是频道或流媒体我拥有的.
我希望可以使用某种方式使用 YouTubeService_V3 从广播ID查找LiveChatID,然后能够使用该广播ID从我不拥有的实时流中读取消息
您必须先发送带有频道ID的 youtube/v3/search 请求.获得实时视频ID后,您必须发送带有视频ID的 youtube/v3/videos 请求,然后才能获得liveChatID ...这是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
我希望有一种更好的方法,因为仅此一项,搜索"就占了您的配额的100分,而Google仅给了您10,000分.
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
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...
这篇关于无法从我不拥有的信息流中获得实时聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!