童话故事集 API:故事详情接入点(1700-3)怎么用?用 id 取全文
# 童话故事集 API:故事详情接入点(1700-3)怎么用?用 id 取全文
> 元信息:童话故事集 API(apiCode=1700)· 接入点 1700-3 · 免费服务 · 返回 JSON · 适用人群:需展示故事正文的开发者 · 阅读时间约 5 分钟
## 核心要点
- 1700-3 只有一个必填参数 `id`,来自 1700-2 列表返回的 `contentlist[].id`。
- 返回包含 `title`(标题)、`classify/classifyId`(分类)、`content`(正文)等字段。
- `content` 是长文本,前端展示注意换行、截断与 XSS 转义。
## Why:详情是用户最终消费的内容
列表只是"书目",详情才是"书"。用户在列表里点了一篇故事,你就要用它的 `id` 调 1700-3,把标题、分类和正文 `content` 完整呈现出来。本篇讲清参数、返回与展示要点。
## What:接口速览
| 项目 | 说明 |
|------|------|
| 接口地址 | `https://route.showapi.com/1700-3?appKey=YOUR_APPKEY` |
| 必填参数 | `id`(故事 id,来自 1700-2) |
| 返回字段 | `title / classify / classifyId / content / id` |
| 计费 | 免费 |
## How:用 id 取详情
```python
import requests
APPKEY = "YOUR_APPKEY"
url = f"https://route.showapi.com/1700-3?appKey={APPKEY}"
def get_story(story_id):
r = requests.post(url, data={"id": story_id},
headers={"content-type": "application/x-www-form-urlencoded"}, timeout=10)
body = r.json()["showapi_res_body"]
if body.get("ret_code") != "0":
raise SystemExit(body.get("remark"))
return body
story = get_story("5ba1c5bfc1b4be0a124a8445")
print(story["title"])
print("分类:", story["classify"])
print(story["content"])
```
```bash
curl -X POST "https://route.showapi.com/1700-3?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "id=5ba1c5bfc1b4be0a124a8445"
```
```javascript
const r = await fetch(`https://route.showapi.com/1700-3?appKey=YOUR_APPKEY`, {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({ id: "5ba1c5bfc1b4be0a124a8445" }),
});
const story = (await r.json()).showapi_res_body;
console.log(story.title, story.classify, story.content);
```
## 返回示例与解析
```json
{
"showapi_res_body": {
"ret_code": "0",
"remark": "查询成功!",
"classify": "安徒生童话",
"classifyId": "2",
"content": "你大概听说过...",
"title": "踩面包的姑娘",
"id": "5ba1c5bfc1b4be0a124a8445"
}
}
```
| 字段 | 含义 |
|------|------|
| `id` | 故事 id(与请求入参一致) |
| `title` | 故事名称 |
| `classify` / `classifyId` | 分类名称 / 分类 Id |
| `content` | 故事正文(长文本) |
## 进阶 / 边界
- **id 来自列表**:`id` 不是随便编的,必须是 1700-2 `contentlist[].id` 的真实值;缓存时把它作为 key。
- **content 是纯文本**:接口返回的是故事正文文本,不含 HTML 样式。前端要自己处理段落换行(按 `\n` 或标点切分)、字体与配图位。
- **内容安全**:`content` 渲染到网页前务必做转义,防止存储型 XSS(详见[故事分享平台实践](https://www.showapi.com/guides/child-story-platform-guide-1700))。
## FAQ
**Q: id 从哪里来?**
A: 来自 1700-2 故事列表返回的 `contentlist[].id`,不要自己构造。
**Q: 详情接口也会分页吗?**
A: 不会。1700-3 只返回单篇故事,分页字段只在 1700-2 出现。
**Q: content 里没有插图,怎么丰富展示?**
A: 接口只提供文字正文,配图需接入方自行准备(如按分类/标题配图),正文本身不含图片。
**Q: 同一个 id 反复取详情会限流吗?**
A: 免费服务有档次限制,详情正文变化频率低,建议服务端按 id 缓存(见[缓存策略](https://www.showapi.com/guides/child-story-cache-1700))。
## 相关能力 / 下一步阅读
- [童话故事集 API:故事列表搜索与分页实战](https://www.showapi.com/guides/child-story-list-guide-1700)
- [免费接口也别乱调用:内容缓存与分页拉取策略](https://www.showapi.com/guides/child-story-cache-1700)
- [故事分享平台如何接入童话故事集 API](https://www.showapi.com/guides/child-story-platform-guide-1700)
- **本系列共 12 篇**:查看[童话故事集 API 指南总目录](https://www.showapi.com/guides/child-story-guides-1700)