Google Search Console
2026-03-27
新闻来源:网淘吧
围观:13
电脑广告
手机广告
Google Search Console
通过托管的OAuth身份验证访问Google Search Console API。查询搜索分析、管理网站地图,并监控网站在Google搜索中的表现。
快速入门
# List sites
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/google-search-console/webmasters/v3/sites')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
基础URL
https://gateway.maton.ai/google-search-console/{native-api-path}
将{native-api-path}替换为实际的Google Search Console API端点路径。网关将请求代理到www.googleapis.com并自动注入您的OAuth令牌。
身份验证
所有请求都需要在Authorization头部中包含Maton API密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的API密钥设置为MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
获取您的API密钥
连接管理
请在https://ctrl.maton.ai管理您的 Google OAuth 连接。
列出连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=google-search-console&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
创建连接
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'google-search-console'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
获取连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
{
"connection": {
"connection_id": "21fd90f9-5935-43cd-b6c8-bde9d915ca80",
"status": "ACTIVE",
"creation_time": "2025-12-08T07:20:53.488460Z",
"last_updated_time": "2026-01-31T20:03:32.593153Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "google-search-console",
"metadata": {}
}
}
在浏览器中打开返回的url以完成 OAuth 授权。
删除连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
指定连接
如果您有多个 Google Search Console 连接,请使用Maton-Connection请求头来指定要使用哪一个:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/google-search-console/webmasters/v3/sites')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '21fd90f9-5935-43cd-b6c8-bde9d915ca80')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最早创建的)活动连接。
API 参考
站点
GET /google-search-console/webmasters/v3/sites
GET /google-search-console/webmasters/v3/sites/{siteUrl}
注意:站点 URL 必须进行 URL 编码(例如,https%3A%2F%2Fexample.com%2F)。
搜索分析
POST /google-search-console/webmasters/v3/sites/{siteUrl}/searchAnalytics/query
Content-Type: application/json
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["query"],
"rowLimit": 100
}
站点地图
GET /google-search-console/webmasters/v3/sites/{siteUrl}/sitemaps
PUT /google-search-console/webmasters/v3/sites/{siteUrl}/sitemaps/{feedpath}
DELETE /google-search-console/webmasters/v3/sites/{siteUrl}/sitemaps/{feedpath}
搜索分析示例
热门查询
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["query"],
"rowLimit": 25
}
热门页面
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["page"],
"rowLimit": 25
}
设备细分
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["device"],
"rowLimit": 10
}
每日表现
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["date"],
"rowLimit": 31
}
筛选查询
{
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"dimensions": ["query"],
"dimensionFilterGroups": [{
"filters": [{
"dimension": "query",
"operator": "contains",
"expression": "keyword"
}]
}],
"rowLimit": 100
}
维度
查询词- 搜索查询词页面- 页面网址国家/地区- 国家/地区代码设备- 桌面设备、移动设备、平板电脑日期- 日期
指标(自动返回)
点击次数- 点击次数展示次数- 展示次数点击率- 点击率排名位置- 平均排名
代码示例
JavaScript
const response = await fetch(
'https://gateway.maton.ai/google-search-console/webmasters/v3/sites/https%3A%2F%2Fexample.com/searchAnalytics/query',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
},
body: JSON.stringify({
startDate: '2024-01-01',
endDate: '2024-01-31',
dimensions: ['query'],
rowLimit: 25
})
}
);
Python
import os
import requests
from urllib.parse import quote
site_url = quote('https://example.com', safe='')
response = requests.post(
f'https://gateway.maton.ai/google-search-console/webmasters/v3/sites/{site_url}/searchAnalytics/query',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
json={
'startDate': '2024-01-01',
'endDate': '2024-01-31',
'dimensions': ['query'],
'rowLimit': 25
}
)
注意事项
- 网站URL在路径中必须进行URL编码
- 日期范围限制为16个月
- 每次请求最多25,000行数据
- 使用
起始行数进行分页 - 数据有2-3天的延迟
- 重要提示:使用curl命令时,如果URL包含方括号(
字段[]、排序[]、记录[]),请使用curl -g以禁用通配符解析 - 重要提示:将curl输出通过管道传递给
jq或其他命令时,环境变量如$MATON_API_KEY在某些Shell环境中可能无法正确展开。通过管道传输时,您可能会遇到"无效的API密钥"错误。
错误处理
| 状态码 | 含义 |
|---|---|
| 400 | 缺少Search Console连接 |
| 401 | Maton API密钥无效或缺失 |
| 429 | 请求频率受限(每个账户每秒10次请求) |
| 4xx/5xx | 来自Search Console API的透传错误 |
故障排除:API密钥问题
- 请检查
MATON_API_KEY环境变量是否已设置:
echo $MATON_API_KEY
- 通过列出连接来验证API密钥是否有效:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
故障排除:无效的应用名称
- 请确保您的URL路径以
google-search-console开头。例如:
- 正确示例:
https://gateway.maton.ai/google-search-console/webmasters/v3/sites - 错误:
https://gateway.maton.ai/webmasters/v3/sites
资源
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~