douyinWEB/docs/YPP_REVENUE_API.md
eric 0dc70fdded Document YouTube YPP revenue API research (Analytics monetary scope).
Clarify AdSense doc is site ads only; channel earnings use yt-analytics-monetary.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-07 20:50:29 -05:00

72 lines
4.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# YouTube YPP 频道创收 API 调研(仅分析,未接入)
结论:**可以**通过官方 API 拉取 **YPP(YouTube Partner Program)频道预估创收**,正确入口是 **YouTube Analytics API**(以及可选的 **YouTube Reporting API** 批量报表),**不是** AdSense Management API。
站点 AdSense 与 YPP 频道创收是两套产品;本仓库现有 `ypp_ok` / 上传后开广告属于 Data API 获利设置,**不等于**拉收益数字。
## 官方能力(频道维度)
| 项 | 说明 |
|----|------|
| 主 API | [YouTube Analytics API](https://developers.google.com/youtube/analytics/reference) v2 |
| 方法 | [`reports.query`](https://developers.google.com/youtube/analytics/reference/reports/query) → `GET https://youtubeanalytics.googleapis.com/v2/reports` |
| 频道指定 | `ids=channel==MINE` 或 `ids=channel==UCxxxx`(须对该频道有授权) |
| 核心收益指标 | `estimatedRevenue`(总预估净收入,含广告等 Google 售卖来源) |
| 常用相关指标 | `estimatedAdRevenue`、`estimatedRedPartnerRevenue`(Premium)、`grossRevenue`、`cpm`、`playbackBasedCpm`、`monetizedPlaybacks`、`adImpressions` |
| 维度示例 | `day` / `month`、`country`、`video`、`creatorContentType`(可区分 Shorts vs 长视频等) |
| 货币 | 查询参数 `currency`(ISO 4217,默认 USD) |
概念请求示例:
```text
ids=channel==MINE
startDate=2026-09-01
endDate=2026-09-07
metrics=estimatedRevenue,estimatedAdRevenue,estimatedRedPartnerRevenue
dimensions=day
currency=USD
```
指标说明见:[Metrics – Estimated revenue](https://developers.google.com/youtube/analytics/metrics)。
## 必需 OAuth
拉收益数字时至少需要 **monetary** scope,实践中常还要带上只读频道 scope:
| Scope | 用途 |
|-------|------|
| `https://www.googleapis.com/auth/yt-analytics-monetary.readonly` | **必须**:预估收益 / 广告表现等财务类指标 |
| `https://www.googleapis.com/auth/yt-analytics.readonly` | 观看、订阅等非财务分析(可一并申请) |
| `https://www.googleapis.com/auth/youtube.readonly` | 常见配套;缺了可能报权限不足 |
授权文档:[Authorization](https://developers.google.com/youtube/reporting/guides/authorization)。
**重要**:现有 Shorts/长视频上传用的 YouTube Data API OAuth(upload / force-ssl 等)**默认不含** `yt-analytics-monetary.readonly`。要拉 YPP 收益,需 **扩 scope 并让各频道重新授权**(否则 403)。
## 批量报表(可选)
[YouTube Reporting API](https://developers.google.com/youtube/reporting) 提供系统托管报表(含 Shorts 广告/订阅收入汇总等),适合按日/月批量落盘,不适合秒级仪表盘。Content Owner 级报表还可能需要 `youtubepartner` 与 MCN/内容所有者身份;**单频道运营**一般用 Analytics `reports.query` 即可。
## 限制与注意
1. **预估 vs 结算**:`estimatedRevenue*` 会月终调整;不含 partner-sold / partner-served 部分广告(见官方 Metrics 说明)。
2. **必须是 YPP**:非获利频道即使有 scope,收益指标通常为 0 或不可用。
3. **权限主体**:频道主账号授权;多频道需每个频道(或有管理权限的账号)分别授权。
4. **配额**:与 YouTube Data API 同属 Google Cloud 项目配额体系;适合按小时/天拉取,勿高频轮询。
5. **与本仓库现状**:`yt_long` 的 `ypp_ok` / `ensure_ypp_and_monetize` 只判断能否开广告并设置 monetization,**不读收益**。
## 若将来接入(建议,未实施)
- 独立或扩展 OAuth:在现有上传 token 流程上 **追加** `yt-analytics-monetary.readonly`(+ `youtube.readonly`),强制重新同意。
- 定时按 `channel==UC…` 拉 `estimatedRevenue`(`dimensions=day`),落库按北京日展示;UI 标明「预估」。
- Shorts / 长视频拆分可用 `creatorContentType` 维度(需验证与收益指标的合法组合矩阵)。
- 勿把 monetary refresh token 写入 git。
## 参考链接
- https://developers.google.com/youtube/analytics/reference/reports/query
- https://developers.google.com/youtube/analytics/metrics
- https://developers.google.com/youtube/analytics/reference
- https://developers.google.com/youtube/reporting/guides/authorization
- https://developers.google.com/youtube/reporting/v1/reports/system_managed/shorts