# 单一主题 API 端点应包含 \`image\_url\`

**URL:** https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020
**Category:** Feature
**Created:** [2019年十月15日 09:05 UTC](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020 "2019-10-15T09:05:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ad-si](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@ad-si](https://meta.discourse.org/u/ad-si)
#### Post date: [2019年十月15日 09:05 UTC](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020/1 "2019-10-15T09:05:15Z")

</div>

当您获取带有特定标签的所有主题列表时（例如 [https://meta.discourse.org/tags/ui.json），每个主题都包含一个](https://meta.discourse.org/tags/ui.json%EF%BC%89%EF%BC%8C%E6%AF%8F%E4%B8%AA%E4%B8%BB%E9%A2%98%E9%83%BD%E5%8C%85%E5%90%AB%E4%B8%80%E4%B8%AA) `image_url` 字段。但是，如果只获取单个主题（例如 [https://meta.discourse.org/t/37245.json），则\*不包含](https://meta.discourse.org/t/37245.json%EF%BC%89%EF%BC%8C%E5%88%99*%E4%B8%8D%E5%8C%85%E5%90%AB)\* `image_url` 字段。这有点不一致，如果能提供该字段将对我有很大帮助。您能否将其添加进去？

我目前的临时解决方案是：

```js
response.image_url = (response.post_stream.posts[0].cooked
  .match(/src=\"(.+?)\"/) || [])[1]

```

---

<div class="post-metadata">

### Author: ![Parker1090](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/parker1090/32/119862_2.png) [@Parker1090](https://meta.discourse.org/u/Parker1090)
#### Post date: [2019年十月21日 21:27 UTC](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020/2 "2019-10-21T21:27:47Z")

</div>

我刚刚看到这个帖子，也在找同样的东西。

有人知道有没有办法添加这个（例如通过插件）吗？

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [2019年十月22日 04:18 UTC](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020/3 "2019-10-22T04:18:41Z")

</div>

我创建了一个提交，为话题序列化器添加了 image\_url：

> <https://github.com/discourse/discourse/commit/3201613f138bf574577d77631f8214098e22b7e3>
>
> The \`image\_url\` is already included when fetching a list of topics, and
> this com…mit adds it to the individual topic serializer so that it is
> available via the api.
> 
> See
> 
> https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020
> 
> for more details.

---

<div class="post-metadata">

### Author: ![Parker1090](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/parker1090/32/119862_2.png) [@Parker1090](https://meta.discourse.org/u/Parker1090)
#### Post date: [2019年十月22日 22:38 UTC](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020/4 "2019-10-22T22:38:47Z")

</div>

太棒了！谢谢 @blake！👍

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [2020年十一月28日 08:09 UTC](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020/5 "2020-11-28T08:09:38Z")

</div>

我可以使用 `/search.json?q=loreal&image_url=true` 吗？

我想在搜索主题时，在返回的 JSON 结果中显示 image\_url。
