You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过YouTube API(YT API)检测提及内容?优先支持Atom/RSS

检测YouTube内容中的提及信息(优先Atom/RSS方案)

一、Atom/RSS订阅方案

YouTube支持为特定搜索结果生成RSS/Atom feed,这是无需API密钥就能实现提及检测的轻量方案:

  • 生成目标搜索的RSS链接
    直接构造格式如下的链接,将[关键词]替换为你要检测的提及内容(多关键词用+连接,比如your+brand+name):
    https://www.youtube.com/feeds/videos.xml?search_query=[关键词]

  • 定期拉取并解析feed
    用脚本(比如Python的feedparser库)定时请求这个链接,解析XML内容后检查视频标题、描述是否包含目标提及,匹配成功就提取视频URL:

    import feedparser
    import time
    
    def check_mentions():
        # 替换为你的目标关键词链接
        feed_url = "https://www.youtube.com/feeds/videos.xml?search_query=your+target+term"
        feed = feedparser.parse(feed_url)
        for entry in feed.entries:
            video_title = entry.title
            video_url = entry.link
            video_description = entry.description
            # 匹配关键词(不区分大小写)
            if "your target term" in video_title.lower() or "your target term" in video_description.lower():
                print(f"检测到提及:{video_title} - {video_url}")
    
    # 每小时执行一次检测
    while True:
        check_mentions()
        time.sleep(3600)
    
  • 注意事项

    • RSS feed更新有延迟,通常在视频发布后数分钟到数小时同步
    • 搜索结果可能包含无关内容,建议结合更精准的关键词匹配逻辑过滤

二、YouTube Data API补充方案(RSS满足不了需求时用)

如果需要更精准的检测(比如结合视频标签等维度),可以用YouTube Data API的search.list接口:

  • 获取API密钥
    在Google Cloud Console创建项目,启用YouTube Data API v3,生成专属API密钥。

  • 调用搜索接口检测提及
    构造请求参数搜索目标关键词,再提取匹配视频的URL:

    import requests
    
    API_KEY = "your_api_key"
    TARGET_TERM = "your target term"
    
    def search_youtube_mentions():
        search_url = "https://www.googleapis.com/youtube/v3/search"
        search_params = {
            "key": API_KEY,
            "q": TARGET_TERM,
            "type": "video",
            "part": "id,snippet",
            "maxResults": 50
        }
        response = requests.get(search_url, params=search_params)
        results = response.json()
    
        for item in results.get("items", []):
            video_id = item["id"]["videoId"]
            video_title = item["snippet"]["title"]
            video_description = item["snippet"]["description"]
            video_url = f"https://www.youtube.com/watch?v={video_id}"
            if TARGET_TERM.lower() in video_title.lower() or TARGET_TERM.lower() in video_description.lower():
                print(f"检测到提及:{video_title} - {video_url}")
    
    search_youtube_mentions()
    

三、推送通知的替代方案

YouTube官方推送通知(Webhook)仅支持订阅频道更新或特定视频的评论更新,无法直接基于关键词提及触发推送。你可以结合上述RSS/API方案,自己实现定时检测+自定义通知(比如邮件、内部消息推送)。


内容的提问来源于stack exchange,提问作者WalkTheEarth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 08:29:56