# 如何动态获取 Discourse 主题 ID 列表

**URL:** https://meta.discourse.org/t/how-can-i-get-the-list-of-discourse-topic-ids-dynamically/162158
**Category:** Development
**Created:** [2020 年8 月 26 日 18:00 UTC](https://meta.discourse.org/t/how-can-i-get-the-list-of-discourse-topic-ids-dynamically/162158 "2020-08-26T18:00:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Duksh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/duksh/32/191282_2.png) [@Duksh](https://meta.discourse.org/u/Duksh)
#### Post date: [2020 年8 月 26 日 18:00 UTC](https://meta.discourse.org/t/how-can-i-get-the-list-of-discourse-topic-ids-dynamically/162158/1 "2020-08-26T18:00:43Z")

</div>

继续讨论 [通过 JavaScript 嵌入 Discourse 评论](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963)：

> [@eviltrout](#):
>
> ` topicId: 12345 };`

我应该从 PHP 函数调用哪个 Discourse API，以便在 CMS 的可搜索下拉框中加载所有 Discourse 主题 ID？

谢谢

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2020 年8 月 26 日 22:12 UTC](https://meta.discourse.org/t/how-can-i-get-the-list-of-discourse-topic-ids-dynamically/162158/2 "2020-08-26T22:12:07Z")

</div>

你可以通过向 `/latest.json` 发送请求来获取主题 ID。每次对该路由的请求将返回 30 个主题。在初始请求之后，使用返回的 `more_topics_url` 值来获取下一批主题，例如 `/latest?no_definitions=true&page=1`。你可以在请求返回的 `topic_list` 对象中找到 `more_topics_url`。

你可以在请求返回的 `topics` 数组中找到主题 ID。

如果你的 Discourse 站点已安装 [Data Explorer 插件](https://meta.discourse.org/t/data-explorer-plugin/32566)，你也可以尝试编写一个 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 查询以返回你感兴趣的主题 ID，然后 [通过 Discourse API 运行 Data Explorer 查询](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-the-discourse-api/120063)。

---

<div class="post-metadata">

### Author: ![Duksh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/duksh/32/191282_2.png) [@Duksh](https://meta.discourse.org/u/Duksh)
#### Post date: [2020 年8 月 27 日 03:53 UTC](https://meta.discourse.org/t/how-can-i-get-the-list-of-discourse-topic-ids-dynamically/162158/3 "2020-08-27T03:53:23Z")

</div>

谢谢 @simon 👍
