douyinWEB/docs/ADSENSE_API.md
eric 1d35f485c6 Update README for global quotas, live receiving-first, and branch notes.
Add AdSense Management API research doc (analysis only, not integrated).

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

45 lines
2.7 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.

# AdSense 收益数据 API 调研(仅分析,未接入)
结论先说:**可以通过 Google 官方 API 拿到 AdSense 收益相关数据**,主要是报表里的 **预估收益(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) |
典型请求形态(概念):
- `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