How to get current number of viewers for specific live video with YouTube API?

为君一笑 提交于 2019-12-08 06:11:15

问题


How to get current number of viewers for live video with YouTube API?

I can see number of current viewers using request for feed of videos like this: https://gdata.youtube.com/feeds/api/charts/live/events/live_now?v=2&alt=json&inline=true&max-results=20&start-index=1

It returns me random videos, but I need to get current viewers for specific video. So when I using request for video ( like this https://gdata.youtube.com/feeds/api/videos/fWuS8hM_5D8?v=2&alt=json ) there is no currentViewers field, onlie viewCount.

Is there any solution of this issue?


回答1:


This is now possible with V3 of the YouTube API ... you request the videos object, passing in the videoID that represents the live stream, and ask for the "liveStreamingDetails" part. One of the parameters returned will be "concurrentViewers" -- for more info:

https://developers.google.com/youtube/v3/docs/videos#liveStreamingDetails.concurrentViewers




回答2:


It's not possible at this time. This kind of public informations are not share with the API YouTube.

From the @Jeff Posnick answer :

Unfortunately, while that data is available in a backend that the YouTube web interface can access, it's not exposed at all via any API (YT Data API v1/v2/v3 or YT Analytics API) at this time.




回答3:


GET https://www.googleapis.com/youtube/v3/videos?part=liveStreamingDetails&id={YT ID}&fields=items%2FliveStreamingDetails%2FconcurrentViewers&key={YOUR_API_KEY}

You must get unique google api key (at first read here: https://developers.google.com/youtube/v3/getting-started ). After you can get any metrics (more read here: https://developers.google.com/youtube/v3/docs/videos#liveStreamingDetails.concurrentViewers ). In my example i getting just one metric (concurrentViewers) where {YT ID} - youtube video id and {YOUR_API_KEY} - your api key.



来源:https://stackoverflow.com/questions/25931555/how-to-get-current-number-of-viewers-for-specific-live-video-with-youtube-api

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