Google Search Console CLI Skill
Use this skill to operate and troubleshoot the gsc CLI in this repository.
When To Use
Use this skill when the task involves any of:
- - setting up OAuth credentials for Google Search Console
- authenticating this CLI
- listing properties, managing sitemaps, URL inspection, or Search Analytics queries
- diagnosing auth/config/API connectivity issues
Prerequisites
- - Python environment with this project installed (
gsc command available) - A Google account with access to at least one Search Console property
- Search Console API enabled for the Google Cloud project used by OAuth
Install This CLI
Recommended (pipx, global gsc command):
CODEBLOCK0
From source (development):
CODEBLOCK1
From source (pipx, editable):
CODEBLOCK2
OAuth Client Setup In Google Cloud (Desktop App)
As of February 26, 2026, create OAuth client credentials in Google Cloud Console using these steps:
- 1. Open Google Cloud Console and select/create a project.
- Enable the Search Console API for that project.
- Configure OAuth consent screen:
- choose
External for personal/testing usage (or
Internal for Workspace org-only)
- fill required app fields (app name, support email, developer contact)
- add your Google account as a test user if app is in testing mode
- 4. Go to
APIs & Services -> Credentials. - Click
Create credentials -> OAuth client ID. - Choose application type
Desktop app. - Create and download the OAuth client JSON (
client_secret_*.json).
Notes:
- - UI labels can shift, but you must end with a Desktop OAuth client JSON file.
- Keep the downloaded JSON private.
Authenticate This CLI
Preferred login flow:
CODEBLOCK3
Useful auth options:
- -
--readonly: request readonly scope only (webmasters.readonly) - INLINECODE15 : print the auth URL without auto-opening a browser
Verify credentials:
CODEBLOCK4
Default storage paths:
- - credentials: INLINECODE16
- app config: INLINECODE17
Env overrides:
- - INLINECODE18
- INLINECODE19
- INLINECODE20
Optional: Set Default Property
CODEBLOCK5
When set, commands that accept --site can omit it.
Command Reference
Top-level:
- - INLINECODE22
- INLINECODE23
- INLINECODE24
auth
- - INLINECODE26
- INLINECODE27
config
- - INLINECODE29
- INLINECODE30
site
- - INLINECODE32
- INLINECODE33
- INLINECODE34
INLINECODE35 example: sc-domain:example.com.
sitemap
- - INLINECODE38
- INLINECODE39
- INLINECODE40
- INLINECODE41
INLINECODE42 alias: --path.
url
Defaults:
analytics
Options:
- - INLINECODE49
- INLINECODE50 (repeatable)
- INLINECODE51
- INLINECODE52
- INLINECODE53
- INLINECODE54
- INLINECODE55
- INLINECODE56 (repeatable)
- INLINECODE57
- INLINECODE58
Supported filter dimensions:
- -
country, device, page, query, INLINECODE63
Supported filter operators:
- -
contains, equals, notContains, notEquals, includingRegex, INLINECODE69
Constraint:
- -
--aggregation-type byProperty cannot be combined with page dimension or page filter.
Quick Examples
CODEBLOCK6
Troubleshooting
- Re-run login with needed scope. For write commands, run login without
--readonly.
- Run: INLINECODE76
- pass
--site or set default via INLINECODE79
- - API failures / uncertain setup state
- run
gsc doctor first, then address failing checks.
Google Search Console CLI 技能
使用此技能来操作和排查此仓库中的 gsc CLI。
使用时机
当任务涉及以下任何内容时,使用此技能:
- - 为 Google Search Console 设置 OAuth 凭据
- 验证此 CLI
- 列出属性、管理站点地图、URL 检查或搜索分析查询
- 诊断身份验证/配置/API 连接问题
前提条件
- - 已安装此项目的 Python 环境(gsc 命令可用)
- 拥有至少一个 Search Console 属性访问权限的 Google 账号
- 为 OAuth 使用的 Google Cloud 项目启用 Search Console API
安装此 CLI
推荐方式(pipx,全局 gsc 命令):
bash
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install google-search-console-cli
gsc --version
从源码安装(开发模式):
bash
python3 -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
gsc --help
从源码安装(pipx,可编辑模式):
bash
pipx install -e /absolute/path/to/google-search-console-cli
gsc --help
在 Google Cloud 中设置 OAuth 客户端(桌面应用)
截至 2026 年 2 月 26 日,按照以下步骤在 Google Cloud Console 中创建 OAuth 客户端凭据:
- 1. 打开 Google Cloud Console 并选择/创建一个项目。
- 为该项目启用 Search Console API。
- 配置 OAuth 同意屏幕:
- 个人/测试用途选择 External(仅限 Workspace 组织选择 Internal)
- 填写必填应用字段(应用名称、支持邮箱、开发者联系方式)
- 如果应用处于测试模式,将您的 Google 账号添加为测试用户
- 4. 进入 APIs & Services -> Credentials。
- 点击 Create credentials -> OAuth client ID。
- 选择应用类型 Desktop app。
- 创建并下载 OAuth 客户端 JSON 文件(clientsecret*.json)。
注意:
- - UI 标签可能会变化,但最终必须获得桌面 OAuth 客户端 JSON 文件。
- 请妥善保管下载的 JSON 文件。
验证此 CLI
推荐登录流程:
bash
gsc auth login --client-secret /absolute/path/to/client_secret.json
有用的身份验证选项:
- - --readonly:仅请求只读范围(webmasters.readonly)
- --no-launch-browser:打印身份验证 URL 而不自动打开浏览器
验证凭据:
bash
gsc auth whoami
gsc doctor
默认存储路径:
- - 凭据:~/.config/gsc-cli/credentials.json
- 应用配置:~/.config/gsc-cli/config.json
环境变量覆盖:
- - GSCCREDENTIALSFILE
- GSCAPPCONFIGFILE
- GSCCONFIG_DIR
可选:设置默认属性
bash
gsc config set default-site sc-domain:example.com
gsc config get default-site
设置后,接受 --site 的命令可以省略该参数。
命令参考
顶层命令:
- - gsc --version
- gsc --help
- gsc doctor
auth
- - gsc auth login --client-secret FILE [--readonly] [--no-launch-browser]
- gsc auth whoami [--output table|json]
config
- - gsc config set default-site SITE_URL
- gsc config get default-site
site
- - gsc site list [--output table|json|csv] [--csv-path FILE]
- gsc site get [--site SITE] [--output table|json|csv] [--csv-path FILE]
- gsc site add [--site SITE]
SITE 示例:sc-domain:example.com。
sitemap
- - gsc sitemap list [--site SITE] [--sitemap-index TEXT] [--output table|json|csv] [--csv-path FILE]
- gsc sitemap get [--site SITE] --feedpath TEXT [--output table|json|csv] [--csv-path FILE]
- gsc sitemap submit [--site SITE] --feedpath TEXT
- gsc sitemap delete [--site SITE] --feedpath TEXT
--feedpath 别名:--path。
url
- - gsc url inspect [--site SITE] --url URL [--language-code CODE] [--output table|json|csv] [--csv-path FILE]
默认值:
analytics
- - gsc analytics query --start-date YYYY-MM-DD --end-date YYYY-MM-DD [options]
选项:
- - --site SITE
- --dimension country|date|device|hour|page|query|searchAppearance(可重复)
- --type discover|googleNews|image|news|video|web
- --aggregation-type auto|byNewsShowcasePanel|byPage|byProperty
- --row-limit 1..25000
- --start-row >=0
- --data-state all|final|hourly_all
- --filter dimension:operator:expression(可重复)
- --output table|json|csv
- --csv-path FILE
支持的筛选维度:
- - country、device、page、query、searchAppearance
支持的筛选运算符:
- - contains、equals、notContains、notEquals、includingRegex、excludingRegex
约束:
- - --aggregation-type byProperty 不能与 page 维度或 page 筛选器同时使用。
快速示例
bash
列出属性
gsc site list
获取单个属性
gsc site get --site sc-domain:example.com
列出站点地图
gsc sitemap list --site sc-domain:example.com
检查单个 URL
gsc url inspect --site sc-domain:example.com --url https://example.com/page --output json
分析查询
gsc analytics query \
--site sc-domain:example.com \
--start-date 2026-01-01 \
--end-date 2026-01-31 \
--dimension date \
--dimension query \
--filter query:contains:brand
故障排除
- - Auth error: Stored credentials do not include required scope ...
- 使用所需范围重新运行登录。对于写入命令,运行登录时不加 --readonly。
- - No local OAuth credentials found...
- 运行:gsc auth login --client-secret
- - No site specified. Pass --site or set one...
- 传递 --site 或通过 gsc config set default-site ... 设置默认值
- 首先运行 gsc doctor,然后处理失败的检查。