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>
This commit is contained in:
eric 2026-09-07 20:50:29 -05:00
parent 1d35f485c6
commit 0dc70fdded
3 changed files with 79 additions and 38 deletions

View File

@ -431,9 +431,9 @@ Windows 上可用 `python scripts\_deploy.py`(需自行配置 SSH 目标,**
分配页「排除手动直播名单」:已用于手动开播的抖音房不再被时段自动挑选 / 日程自动填充。API:`/api/youtube/assign/timeslot-exclude*`。
#### AdSense 收益 API(调研)
#### YouTube YPP 频道创收 API(调研)
官方 **可以**通过 [AdSense Management API](https://developers.google.com/adsense/management/getting_started) 拉取**预估收益**等报表(`accounts.reports.generate` + `ESTIMATED_EARNINGS`)。本仓库**尚未接入**;分析结论见 [docs/ADSENSE_API.md](docs/ADSENSE_API.md)。
官方 **可以**通过 [YouTube Analytics API](https://developers.google.com/youtube/analytics/reference/reports/query) 拉取频道 **预估创收**(`estimatedRevenue` 等),需 OAuth scope `yt-analytics-monetary.readonly`。本仓库当前 Shorts OAuth **未包含**该 scope,也**尚未接入**收益拉取。分析结论见 [docs/YPP_REVENUE_API.md](docs/YPP_REVENUE_API.md)。(站点 AdSense 是另一套 API,见 [docs/ADSENSE_API.md](docs/ADSENSE_API.md)。)
- **不复用** sh2 RTMP 转播通道
### 封面(S3)
@ -490,7 +490,7 @@ douyinWEB/
desktop/ Windows Electron 客户端(本机 PB+API+UI)
youtube-svc/ YouTube.js sidecar(InnerTube)
pb/ PocketBase 数据与 migrations
docs/ 专题文档(Shorts、物理机部署、AdSense API 调研等);全局 SOCKS5 方案见 README
docs/ 专题文档(Shorts、物理机部署、YPP 创收 / AdSense API 调研等);全局 SOCKS5 方案见 README
scripts/ 本地启动与 VPS 增量部署
```

View File

@ -1,44 +1,14 @@
# AdSense 收益数据 API 调研(仅分析,未接入)
结论先说:**可以通过 Google 官方 API 拿到 AdSense 收益相关数据**,主要是报表里的 **预估收益(ESTIMATED_EARNINGS)**,不是银行到账金额的实时流水。
> **YouTube 频道 YPP 创收请看 [YPP_REVENUE_API.md](./YPP_REVENUE_API.md)。**
> 本文只针对 **网站 AdSense**(`adsense.googleapis.com`),与 YPP 频道分成不是同一条 API。
## 官方能力
结论:站点 AdSense **可以**用 [AdSense Management API](https://developers.google.com/adsense/management/getting_started) 拉预估收益(`accounts.reports.generate` + `ESTIMATED_EARNINGS`)。本仓库未接入。
| 项 | 说明 |
|----|------|
| 产品 | [AdSense Management API](https://developers.google.com/adsense/management/reference/rest) v2 |
| 端点 | `https://adsense.googleapis.com` |
| 拉收益 | [`accounts.reports.generate`](https://developers.google.com/adsense/management/reference/rest/v2/accounts.reports/generate) |
| 关键指标 | `ESTIMATED_EARNINGS`(还可配 `CLICKS`、`PAGE_VIEWS`、`COST_PER_CLICK`、`AD_REQUESTS_RPM` 等) |
| 维度示例 | `DATE`、`AD_UNIT_ID`、`COUNTRY_*`、自定义/URL channel 等 |
| OAuth scope | `https://www.googleapis.com/auth/adsense` 或只读 `…/adsense.readonly` |
| 入门 | [Get Started](https://developers.google.com/adsense/management/getting_started) |
| OAuth | `adsense` / `adsense.readonly` |
典型请求形态(概念):
- `date_range`: `YESTERDAY` / `LAST_7_DAYS` / `CUSTOM` + `startDate`/`endDate`
- `metrics`: `ESTIMATED_EARNINGS`
- `dimensions`: `DATE`(或按广告单元过滤)
也可用 Apps Script 高级服务包一层同 API(见 [AdSense Service](https://developers.google.com/apps-script/advanced/adsense))。
## 限制与注意
1. **预估 vs 结算**:API 报表是 **estimated earnings**;最终付款以 AdSense 付款/对账为准,存在延迟与调整。
2. **账号与授权**:须用已开通 AdSense 的 Google 账号 OAuth;Cloud 项目启用 AdSense Management API;首次授权有同意屏。
3. **权限**:只读 scope 足够拉报表;改广告单元等需要完整 `adsense` scope。
4. **配额与频率**:有 API 配额;仪表盘级轮询建议按小时/天聚合,不宜秒级刷。
5. **与 YouTube 收益不是同一条 API**:YouTube Partner Program(频道创收)走 YouTube Analytics / Reporting,**不是** AdSense Management API。站点 AdSense 与 YPP 要分开建模。
6. **合规**:展示/存储收益数据需符合账号服务条款;勿把 refresh token 提交进仓库。
## 若将来接入本仓库(建议,未实施)
- 独立 OAuth / settings 键(勿与 Shorts YouTube OAuth 混用 scope,除非刻意合并同意屏)。
- 后端定时拉 `ESTIMATED_EARNINGS` 按北京日/账号时区落库;前端只读汇总卡。
- 明确文案标注「预估」,避免当成已到账。
## 参考链接
- https://developers.google.com/adsense/management/getting_started
- https://developers.google.com/adsense/management/reference/rest/v2/accounts.reports/generate
- https://developers.google.com/adsense/management/reference/rest
注意:报表是 **estimated**,不是到账流水。

71
docs/YPP_REVENUE_API.md Normal file
View File

@ -0,0 +1,71 @@
# 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