我在使用YouTube API v3获取实时视频ID时遇到问题。我使用“播放列表”查询来从频道中获取当前视频,很好,但是此数据中没有直播。可以通过应用查询“ search”来解决该问题,但是它的权重为100个配额,这不适合我。有谁知道这个问题的可能解决方案?
我解决了这个问题,这是我在python上的代码。
from lxml import html
import requests
page = requests.get(f"https://www.youtube.com/embed/live_stream?channel={channel_id}")
if page.status_code == 200:
tree = html.fromstring(page.content)
links = tree.xpath('//link[@rel="canonical"]')
if links:
id = links[0].attrib['href'].split("watch?v=")[1]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句