技术博客
免费经典语句 API:5 分钟接入,从注册到拿到第一条名言

免费经典语句 API:5 分钟接入,从注册到拿到第一条名言

作者: 万维易源
2026-09-02
免费经典语句API快速接入Python示例AppKey
# 免费经典语句 API:5 分钟接入,从注册到拿到第一条名言 > 元信息:接口 1646-2 · 免费 · 请求方式 POST/GET · 返回 JSON · 适用人群 新注册用户/初级开发者/内容创作者 · 阅读时间 5 分钟 ## 核心要点 - 免费经典语句 API 是**免费**接口,仅需一个 AppKey 即可调用,无需购买资源包。 - 调用极简:请求地址 `https://route.showapi.com/1646-2`,唯一可选参数 `tag`(按主题筛选,如「学习」)。 - 返回 `body`(内容)/ `author`(作者)/ `name`(出处)/ `ret_code`(0 成功),Python/cURL/Node.js 三种代码开箱即用。 ## Why:这跟我有关系吗? 做学习类 App、公众号早安文案、写作灵感插件,经常需要一句恰到好处的名言。自己维护语料库费时费力,而免费经典语句 API 直接给你「内容 + 作者 + 出处」三段式结果,还能按主题筛选。最重要的是——**免费**,试错零成本,先把第一条跑通,再决定怎么集成。 ## What:前置条件与接口速览 **前置条件** - 已注册易源账号(https://www.showapi.com) - 已创建应用并拿到 AppKey(控制台:https://www.showapi.com/console#/myApp) **接口速览** | 项 | 值 | |----|----| | 接口/接入点 | 免费经典语句 · 1646-2(默认分组) | | 请求地址 | `https://route.showapi.com/1646-2?appKey={your_appKey}` | | 请求方式 | POST / GET | | 返回格式 | JSON | | 鉴权 | URL 参数 `appKey` | | 计费 | 免费服务 | | 更新频率 | 持续更新中 | | 集成能力 | MCP、OpenAPI 3.0(YAML/JSON) | ## How:第一次调用 **步骤 1 — 拿 AppKey** 登录后在控制台「我的应用」创建应用,复制 AppKey,替换下面代码里的 `YOUR_APPKEY`。 **步骤 2 — 发送请求(以 `tag=学习` 为例)** Python(requests): ```python import requests url = "https://route.showapi.com/1646-2" params = {"appKey": "YOUR_APPKEY"} data = {"tag": "学习"} # tag 可选;不传则返回默认语句 try: resp = requests.post(url, params=params, data=data, timeout=10) resp.raise_for_status() js = resp.json() except requests.RequestException as e: print("请求失败:", e) raise if js.get("showapi_res_code") != 0: print("系统级错误:", js.get("showapi_res_error")) else: body = js["showapi_res_body"] if body.get("ret_code") != 0: print("业务错误,ret_code =", body.get("ret_code")) else: print("内容:", body.get("body")) print("作者:", body.get("author")) print("出处:", body.get("name")) ``` cURL: ```bash curl -X POST "https://route.showapi.com/1646-2?appKey=YOUR_APPKEY" \ -H "content-type: application/x-www-form-urlencoded" \ -d "tag=%E5%AD%A6%E4%B9%A0" ``` Node.js(fetch): ```javascript const url = "https://route.showapi.com/1646-2?appKey=YOUR_APPKEY"; const form = new URLSearchParams(); form.append("tag", "学习"); // tag 可选 try { const resp = await fetch(url, { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: form, }); const js = await resp.json(); if (js.showapi_res_code !== 0) { console.error("系统级错误:", js.showapi_res_error); } else { const b = js.showapi_res_body; if (b.ret_code !== 0) console.error("业务错误 ret_code=", b.ret_code); else console.log(`${b.body} —— ${b.author}《${b.name}》`); } } catch (e) { console.error("请求失败:", e); } ``` **步骤 3 — 解析返回** `showapi_res_body` 内就是业务数据:`body` 是名言正文,`author` 是作者,`name` 是出处/相关标题。 ## 返回示例与解析 ```json { "showapi_res_error": "", "showapi_fee_num": 1, "showapi_res_code": 0, "showapi_res_id": "6548901d0de3763d6ccb5c1f", "showapi_res_body": { "body": "书山有路勤为径,学海无涯苦作舟。", "author": "韩愈", "ret_code": 0, "name": "古今贤文" } } ``` - `showapi_res_code`:系统级状态码,0 表示请求成功。 - `showapi_res_body.ret_code`:业务状态码,0 表示取到数据。 - `showapi_fee_num`:系统计费标记;本接口为免费服务,不产生费用。 字段含义详见 [免费经典语句 API 返回字段全解](https://www.showapi.com/guides/classic-quotes-fields-1646)。 ## 进阶 / 边界 - **不传 `tag`**:接口返回默认语句,适合「随便来一句」场景。 - **`tag` 可用值**:文档未列出完整标签清单,建议以接口实际返回为准,不要预设固定枚举。 - **单次返回单条**:返回示例为单条 `body`,文档未说明支持批量返回多条,按单条处理即可。 ## FAQ **Q:调用这个接口要花钱吗?** 不需要。免费经典语句 API 是免费服务,注册并创建应用拿到 AppKey 即可调用,无按次/按单费用。 **Q:tag 参数不填会怎样?** 不填 `tag` 时接口返回默认语句,调用依然成功(`ret_code=0`)。`tag` 仅用于按主题筛选。 **Q:返回里的 name 和 author 有什么区别?** `author` 是名言的作者(如「韩愈」),`name` 是该句相关的标题/出处(如「古今贤文」),二者不是同一概念。 **Q:AppKey 泄露了怎么办?** 到控制台「我的应用」重置 AppKey,并立即替换到代码中;不要将真实 AppKey 提交到公开仓库。 **Q:返回的 body 有时候不是我填的 tag 主题?** `tag` 为软筛选,文档未承诺精确匹配;若对主题一致性要求高,建议在客户端做二次过滤或缓存。 ## 相关能力 / 下一步阅读 - [免费经典语句 API 返回字段全解](https://www.showapi.com/guides/classic-quotes-fields-1646) — 读懂 body/author/name/ret_code - [免费经典语句 API 标签筛选:tag 参数怎么用才不出空结果?](https://www.showapi.com/guides/classic-quotes-tag-filter-1646) — 标签用法与空结果排查 - [免费经典语句 API 错误处理](https://www.showapi.com/guides/classic-quotes-error-handling-1646) — 异常与重试 - **本系列共 11 篇**:查看[免费经典语句 API 开发指南总目录](https://www.showapi.com/guides/classic-quotes-guides-1646)