ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何使用搜索 API 构建 YouTube 频道分析器
教程

如何使用搜索 API 构建 YouTube 频道分析器

使用搜索 API 数据而不是昂贵的分析工具来分析 YouTube 频道表现、内容差距和关键字机会。

获取免费API密钥API文档

YouTube 分析工具(vidIQ、TubeBuddy)的频道分析费用为 8-40 美元/月。对于开发人员和数据驱动的创作者来说,搜索 API 提供了原始数据来构建自定义分析:竞争对手的排名、存在内容差距以及哪些关键字竞争较弱。

前置条件

  • Python 3.8+
  • Scavio API 密钥
  • 要分析的目标渠道或关键词

操作指南

步骤 1: 搜索频道内容

查找特定频道中针对目标关键字排名的所有视频。

Python
import requests, os

H = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

def channel_keywords(channel_name: str, keywords: list) -> dict:
    results = {'channel': channel_name, 'rankings': []}
    for kw in keywords:
        resp = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
            json={'platform': 'youtube', 'query': kw}, timeout=10)
        for i, v in enumerate(resp.json().get('organic', [])):
            if channel_name.lower() in v.get('channel', '').lower():
                results['rankings'].append({
                    'keyword': kw, 'position': i + 1,
                    'title': v.get('title', ''), 'views': v.get('views', '')
                })
                break
    return results

步骤 2: 查找内容差距

识别不存在强大视频的关键字(观看次数少或结果很少)。

Python
def find_content_gaps(keywords: list, view_threshold: int = 10000) -> list:
    gaps = []
    for kw in keywords:
        resp = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
            json={'platform': 'youtube', 'query': kw}, timeout=10)
        videos = resp.json().get('organic', [])
        
        # Gap conditions: few results OR top results have low views
        if len(videos) < 5:
            gaps.append({'keyword': kw, 'reason': 'few_videos', 'video_count': len(videos)})
        elif videos and all(int(v.get('views','0').replace(',','') or '0') < view_threshold for v in videos[:3]):
            gaps.append({'keyword': kw, 'reason': 'low_competition', 'top_views': videos[0].get('views','')})
    
    return gaps

步骤 3: 竞争对手分析

将您频道的关键字排名与竞争对手进行比较。

Python
def competitor_comparison(your_channel: str, competitor: str, keywords: list) -> dict:
    your_ranks = channel_keywords(your_channel, keywords)
    their_ranks = channel_keywords(competitor, keywords)
    
    comparison = []
    for kw in keywords:
        your_pos = next((r['position'] for r in your_ranks['rankings'] if r['keyword'] == kw), None)
        their_pos = next((r['position'] for r in their_ranks['rankings'] if r['keyword'] == kw), None)
        comparison.append({
            'keyword': kw,
            'your_position': your_pos,
            'their_position': their_pos,
            'winning': 'you' if (your_pos and their_pos and your_pos < their_pos) else
                      'them' if (their_pos and (not your_pos or their_pos < your_pos)) else 'neither'
        })
    
    return {
        'you': your_channel, 'competitor': competitor,
        'you_winning': sum(1 for c in comparison if c['winning'] == 'you'),
        'them_winning': sum(1 for c in comparison if c['winning'] == 'them'),
        'details': comparison
    }

Python 示例

Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

def yt_rank(keyword, channel):
    r = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'youtube', 'query': keyword}).json()
    for i, v in enumerate(r.get('organic',[])):
        if channel.lower() in v.get('channel','').lower():
            return i + 1
    return None

JavaScript 示例

JavaScript
async function ytRank(keyword, channel) {
  const r = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
    body: JSON.stringify({platform: 'youtube', query: keyword})
  });
  const results = (await r.json()).organic || [];
  const idx = results.findIndex(v => v.channel?.toLowerCase().includes(channel.toLowerCase()));
  return idx >= 0 ? idx + 1 : null;
}

预期输出

JSON
A YouTube channel analyzer that tracks keyword rankings, finds content gaps, and compares performance against competitors using search API data.

相关教程

  • 如何使用搜索 API 跟踪 YouTube 印象衰减

常见问题

大多数开发者在15到30分钟内完成本教程。您需要一个Scavio API密钥(免费套餐即可)和可用的Python或JavaScript环境。

Python 3.8+. Scavio API 密钥. 要分析的目标渠道或关键词. Scavio API密钥注册即送50个免费积分。

可以。免费套餐注册即送50个积分,完全足够完成本教程并构建一个可运行的原型解决方案。

Scavio提供原生LangChain包(langchain-scavio)、MCP服务器以及适用于任何HTTP客户端的REST API。本教程使用 the raw REST API, 但您可以根据需要适配您选择的框架。

相关资源

Best Of

2026 年最佳 YouTube 数据 API

Read more
Best Of

无配额限制的最佳 YouTube 数据 API (2026)

Read more
Solution

API YouTube

Read more
Workflow

YouTube 网红 SERP 研究工作流

Read more
Glossary

YouTube 评论提取

Read more
Comparison

Scavio vs Apify (YouTube actors)

Read more

开始构建

使用搜索 API 数据而不是昂贵的分析工具来分析 YouTube 频道表现、内容差距和关键字机会。

获取免费API密钥阅读文档
ScavioScavio

面向AI智能体的实时搜索API。搜索所有平台,不仅仅是Google。

产品

  • 功能
  • 定价
  • 控制台
  • 联盟计划

开发者

  • 文档
  • API参考
  • 快速开始
  • MCP集成
  • Python SDK

替代方案

  • Tavily替代方案
  • SerpAPI替代方案
  • Firecrawl替代方案
  • Exa替代方案

工具

  • JSON格式化
  • cURL转代码
  • Token计数器
  • 全部工具

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策