Skip to content

feat(auth): request yt-analytics-monetary scope for revenue metrics#21

Merged
jdwit merged 1 commit into
jdwit:mainfrom
maxhuk:feat/monetary-analytics-scope
Jun 7, 2026
Merged

feat(auth): request yt-analytics-monetary scope for revenue metrics#21
jdwit merged 1 commit into
jdwit:mainfrom
maxhuk:feat/monetary-analytics-scope

Conversation

@maxhuk
Copy link
Copy Markdown
Contributor

@maxhuk maxhuk commented Jun 4, 2026

What

Adds https://www.googleapis.com/auth/yt-analytics-monetary.readonly to the OAuth scopes requested at login.

Why

Revenue/earnings reports from the YouTube Analytics API — estimatedRevenue, estimatedAdRevenue, estimatedRedPartnerRevenue, grossRevenue, cpm, playbackBasedCpm, monetizedPlaybacks, adImpressions — require the monetary read scope. Without it, any analytics query that includes a monetary metric fails with 401 "Insufficient permission to access this report."

With the scope present, monetary metrics work; channels not in the YouTube Partner Program simply return empty results (no error), so non-monetized users are unaffected.

Changes

  • src/ytstudio/api.py: add the monetary scope to SCOPES.
  • tests/test_api.py: assert the scope is present.

Note for existing users

After upgrading, re-run ytstudio login to re-consent and pick up the new scope. If OAuthlib complains that the granted scope changed, OAUTHLIB_RELAX_TOKEN_SCOPE=1 ytstudio login resolves it.

The registry already exposes revenue metrics (estimatedRevenue, cpm, ...) but the OAuth flow never requested the monetary scope, so every monetary query returned 401 "Insufficient permission". Add yt-analytics-monetary.readonly to SCOPES so revenue reads work after a re-login, plus a regression test pinning the scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jdwit
Copy link
Copy Markdown
Owner

jdwit commented Jun 7, 2026

Thanks for addressing this!

@jdwit jdwit merged commit 8542ae1 into jdwit:main Jun 7, 2026
7 checks passed
@jdwit jdwit mentioned this pull request Jun 8, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants