主题
OnPage Lighthouse 支持的语言列表
GET /v3/on_page/lighthouse/languages
本接口使用 GET 方法,请求路径为:
text
/v3/on_page/lighthouse/languages用于获取 OnPage Lighthouse API 当前支持的语言列表。调用本接口不会产生费用,扣费以响应头 X-SeerMarTech-Charge-CNY 为准。
请求地址
http
GET https://api.seermartech.cn/v3/on_page/lighthouse/languages本接口无需请求参数,也无需请求体。
认证方式
请求时在 Authorization 请求头中携带 API Key:
http
Authorization: Bearer smt_live_YOUR_KEY响应字段
接口返回 JSON 数据 tasks 数组。
顶层字段
| 字段 | 类型 | 说明 |
|---|---|---|
version | string | 当前 API 版本 |
status_code | integer | 通用状态码 |
status_message | string | 通用状态说明 |
time | string | 请求执行耗时,单位为秒 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
tasks_count | integer | tasks 数组中的任务数量 |
tasks_error | integer | tasks 数组中返回错误的任务数量 |
tasks | array | 任务结果数组 |
tasks 字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 任务唯一标识符,采用 UUID 格式 |
status_code | integer | 任务状态码,取值范围为 10000 至 60000 |
status_message | string | 任务状态说明 |
time | string | 任务执行耗时,单位为秒 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
result_count | integer | result 数组中的数量 |
path | array | 请求 URL 路径 |
data | object | GET 请求 URL 中传递的参数信息 |
result | array | 语言列表结果 |
result 数组字段
| 字段 | 类型 | 说明 |
|---|---|---|
language_name | string | 语言名称 |
language_code | string | 按 ISO 639-1 标准定义的语言代码 |
cURL 示例
bash
curl --location --request GET \
"https://api.seermartech.cn/v3/on_page/lighthouse/languages" \
--header "Authorization: Bearer smt_live_YOUR_KEY" \
--header "Content-Type: application/json"PHP 示例
php
<?php
require('RestClient.php');
$apiUrl = 'https://api.seermartech.cn/';
try {
$client = new RestClient($apiUrl, null, null, null, [
'Authorization' => 'Bearer smt_live_YOUR_KEY'
]);
} catch (RestClientException $e) {
echo "\n";
print "HTTP 状态码: {$e->getHttpCode()}\n";
print "错误码: {$e->getCode()}\n";
print "错误信息: {$e->getMessage()}\n";
exit();
}
try {
// 获取 OnPage Lighthouse 支持的语言列表
// GET /v3/on_page/lighthouse/languages
$result = $client->get('/v3/on_page/lighthouse/languages');
print_r($result);
// 在此处理返回结果
} catch (RestClientException $e) {
echo "\n";
print "HTTP 状态码: {$e->getHttpCode()}\n";
print "错误码: {$e->getCode()}\n";
print "错误信息: {$e->getMessage()}\n";
}
$client = null;
?>TypeScript 示例
typescript
import axios from 'axios';
axios({
method: 'get',
url: 'https://api.seermartech.cn/v3/on_page/lighthouse/languages',
headers: {
Authorization: 'Bearer smt_live_YOUR_KEY',
'Content-Type': 'application/json',
},
})
.then((response) => {
// 处理返回数据
console.log(response.data);
})
.catch((error) => {
console.error('请求失败:', error.response?.data || error.message);
});Python 示例
python
from client import RestClient
client = RestClient(
api_key="smt_live_YOUR_KEY",
base_url="https://api.seermartech.cn"
)
# 获取 OnPage Lighthouse 支持的语言列表
# GET /v3/on_page/lighthouse/languages
response = client.get("/v3/on_page/lighthouse/languages")
if response.get("status_code") == 20000:
print(response)
# 在此处理语言列表
else:
print(
"请求失败。错误码: %s,错误信息: %s"
% (response.get("status_code"), response.get("status_message"))
)如果客户端封不支持直接传 API Key,也可以使用标准 HTTP 客户端,并手动设置以下请求头:
http
Authorization: Bearer smt_live_YOUR_KEY
Content-Type: application/jsonC# 示例
csharp
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace SeerMarTechDemos
{
public static class Demos
{
public static async Task GetOnPageLighthouseLanguages()
{
using var httpClient = new HttpClient
{
BaseAddress = new Uri("https://api.seermartech.cn/")
};
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Bearer",
"smt_live_YOUR_KEY"
);
// 获取 OnPage Lighthouse 支持的语言列表
// GET /v3/on_page/lighthouse/languages
var response = await httpClient.GetAsync(
"/v3/on_page/lighthouse/languages"
);
var content = await response.Content.ReadAsStringAsync();
var result = JObject.Parse(content);
if ((int?)result["status_code"] == 20000)
{
// 在此处理返回结果
Console.WriteLine(result);
}
else
{
Console.WriteLine(
$"请求失败。错误码: {result["status_code"]} " +
$"错误信息: {result["status_message"]}"
);
}
}
}
}响应示例
json
{
"version": "0.1.20220819",
"status_code": 20000,
"status_message": "Ok.",
"time": "0.0667 sec.",
"cost": 0,
"tasks_count": 1,
"tasks_error": 0,
"tasks": [
{
"id": "01234567-89ab-cdef-0123-456789abcdef",
"status_code": 20000,
"status_message": "Ok.",
"time": "0.0123 sec.",
"cost": 0,
"result_count": 2,
"path": [
"v3",
"on_page",
"lighthouse",
"languages"
],
"data": {
"api": "on_page",
"function": "lighthouse"
},
"result": [
{
"language_name": "English",
"language_code": "en"
},
{
"language_name": "Chinese",
"language_code": "zh"
}
]
}
]
}状态码与错误处理
- 顶层
status_code用于表示本次 API 请求的整体处理结果。 tasks[].status_code用于表示任务的处理结果。- 当状态码为
20000时,表示请求成功。 - 可结合
status_message获取的状态说明。 tasks_error用于统计任务级错误数量。- 实扣费以响应头
X-SeerMarTech-Charge-CNY为准。
实用场景
- 校验语言代码:在创建 Lighthouse 审计任务前确认目标语言是否受支持,因传无效语言代码导致任务失败。
- 构建多语言 SEO 审计系统:动态获取可用语言列表,为不同国家或地区的网站选择对应的 Lighthouse 分析语言。
- 生成语言选择器:在 SEO 管理后台展示标准化语言名称和 ISO 639-1 代码,提升用户审计任务的准确性。
- 同步平台能力:定期读取最新语言列表并更新本地缓存,确保业务系统与平台 API 的语言支持范围保持一致。