diff --git a/src/ytstudio/api.py b/src/ytstudio/api.py index 48f11f6..178be14 100644 --- a/src/ytstudio/api.py +++ b/src/ytstudio/api.py @@ -63,6 +63,10 @@ def api(request): "https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/youtube.force-ssl", "https://www.googleapis.com/auth/yt-analytics.readonly", + # Required to read revenue/earnings metrics (estimatedRevenue, cpm, ...). + # Without it the Analytics API returns 401 "Insufficient permission" for + # the monetary metrics that the registry already exposes. + "https://www.googleapis.com/auth/yt-analytics-monetary.readonly", ] HEADLESS_REDIRECT_URI = "http://127.0.0.1:9876/" diff --git a/tests/test_api.py b/tests/test_api.py index 076a444..a063243 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -20,6 +20,13 @@ def make_http_error(status: int, reason: str = ""): return error +class TestScopes: + def test_includes_monetary_analytics_scope(self): + # Revenue/earnings metrics (estimatedRevenue, cpm, ...) require this + # scope; without it the Analytics API returns 401 for monetary reports. + assert "https://www.googleapis.com/auth/yt-analytics-monetary.readonly" in api_module.SCOPES + + class TestHandleApiError: def test_quota_exceeded_exits(self): error = make_http_error(403, "quotaExceeded")