Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ytstudio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down