ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何使用搜索 API 跟踪 YouTube 印象衰减
教程

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

使用搜索 API 跟踪 YouTube 视频在搜索排名中的下降情况。无需访问 YouTube 分析工具即可构建展示次数衰减跟踪器。

获取免费API密钥API文档

YouTube 的展示次数在发布后就会衰减:视频在几天内就在搜索可见度中达到顶峰,然后随着新内容的竞争而逐渐下降。跟踪这种衰减有助于创作者了解其内容的保质期。本教程使用每日 API 查询而不是依赖 YouTube Studio(仅显示您自己的视频)来跟踪一段时间内的搜索位置。

前置条件

  • Python 3.8+
  • Scavio API 密钥
  • 要跟踪的视频 URL 或关键字

操作指南

步骤 1: 跟踪关键字的搜索位置

每天查询 YouTube 搜索并记录您的视频排名。

Python
import requests, os, json
from datetime import date

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

def track_position(keyword: str, target_channel: str) -> dict:
    resp = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'youtube', 'query': keyword}, timeout=10)
    results = resp.json().get('organic', [])
    
    for i, r in enumerate(results):
        if target_channel.lower() in r.get('channel', '').lower():
            return {'keyword': keyword, 'position': i + 1, 'date': date.today().isoformat(),
                    'title': r.get('title', ''), 'views': r.get('views', '')}
    
    return {'keyword': keyword, 'position': None, 'date': date.today().isoformat(), 'not_found': True}

步骤 2: 建立每日跟踪循环

每天跟踪多个关键字并存储位置历史记录。

Python
from pathlib import Path

def daily_rank_track(keywords: list, channel: str) -> dict:
    history_file = Path('yt_rank_history.json')
    history = json.loads(history_file.read_text()) if history_file.exists() else {}
    
    today = date.today().isoformat()
    today_data = []
    
    for kw in keywords:
        position = track_position(kw, channel)
        today_data.append(position)
    
    history[today] = today_data
    history_file.write_text(json.dumps(history, indent=2))
    
    return {'date': today, 'tracked': len(keywords), 'found': sum(1 for d in today_data if d.get('position')),
            'positions': today_data}

步骤 3: 计算衰减率

分析位置历史记录以计算印象衰减曲线。

Python
def calculate_decay(history: dict, keyword: str) -> dict:
    positions = []
    for day, data in sorted(history.items()):
        for entry in data:
            if entry.get('keyword') == keyword and entry.get('position'):
                positions.append({'date': day, 'position': entry['position']})
    
    if len(positions) < 2:
        return {'keyword': keyword, 'insufficient_data': True}
    
    first_pos = positions[0]['position']
    last_pos = positions[-1]['position']
    days_tracked = len(positions)
    
    decay_rate = (last_pos - first_pos) / days_tracked if days_tracked > 0 else 0
    
    return {
        'keyword': keyword,
        'first_position': first_pos,
        'current_position': last_pos,
        'days_tracked': days_tracked,
        'decay_rate_per_day': round(decay_rate, 2),
        'positions_lost': last_pos - first_pos,
        'trend': 'declining' if decay_rate > 0.1 else 'stable' if abs(decay_rate) < 0.1 else 'improving',
    }

步骤 4: 生成腐烂报告

生成一份总结报告,说明哪些内容衰减最快。

Python
def decay_report(history_file: str = 'yt_rank_history.json') -> dict:
    history = json.loads(Path(history_file).read_text())
    keywords = set()
    for day_data in history.values():
        for entry in day_data:
            if entry.get('keyword'):
                keywords.add(entry['keyword'])
    
    decays = [calculate_decay(history, kw) for kw in keywords]
    decays = [d for d in decays if not d.get('insufficient_data')]
    decays.sort(key=lambda d: d.get('decay_rate_per_day', 0), reverse=True)
    
    return {
        'total_keywords': len(decays),
        'fastest_decaying': decays[:3],
        'most_stable': [d for d in decays if d.get('trend') == 'stable'],
        'improving': [d for d in decays if d.get('trend') == 'improving'],
    }

Python 示例

Python
import requests, os, json
from datetime import date

def track_yt_rank(keyword, channel):
    r = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'},
        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 trackYTRank(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 impression decay tracker that monitors search position daily and calculates decay rates per keyword, identifying content that needs refreshing.

相关教程

  • 如何跟踪 YouTube 播放列表删除情况

常见问题

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

Python 3.8+. Scavio API 密钥. 要跟踪的视频 URL 或关键字. 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
Glossary

搜索 API 供应商格局(2026)

Read more
Comparison

Scavio vs Apify (YouTube actors)

Read more
Comparison

TubeMine vs YouTube Data API (via Scavio)

Read more

开始构建

使用搜索 API 跟踪 YouTube 视频在搜索排名中的下降情况。无需访问 YouTube 分析工具即可构建展示次数衰减跟踪器。

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

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

产品

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

开发者

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

替代方案

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

工具

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

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策