# 使用API获取最后n个新帖/更新的帖子吗？

**URL:** <https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [2024 年5 月 9 日 16:16 UTC](https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427 "2024-05-09T16:16:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

作者： ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
发布日期： [2024 年5 月 9 日 16:57 UTC](https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427/2 "2024-05-09T16:57:51Z")

</div>

> [@Samir\_Sabri](#):
>
> I tried to use APIs to get last n posts using

您是想获取最后 n 个帖子还是最后 n 个主题？

`/latest.json` 将为您提供最新的主题

`/posts.json` 将为您提供所有主题中最新的帖子。

> [@Samir\_Sabri](#):
>
> could not have the URL of each post

您可以根据主题 ID 或帖子 ID 从结果中构建 URL。

例如，此主题的有效 URL 为：[https://meta.discourse.org/t/307427](https://meta.discourse.org/t/307427)，帖子的 URL 为：[https://meta.discourse.org/p/1514266](https://meta.discourse.org/p/1514266)。

> [@Samir\_Sabri](#):
>
> could not strict result to last n posts.

无法更改默认页面大小 30。如果您确实需要少于 30 个，则必须传入特定的主题 ID：

[https://meta.discourse.org/latest.json?topic\_ids[]=307427](https://meta.discourse.org/latest.json?topic_ids%5B%5D=307427)

但您必须事先知道这些主题 ID，所以通常没什么用。如果您想要超过 30 个，则必须发出多个请求并传入 `page` 参数。

[https://meta.discourse.org/latest.json?page=1](https://meta.discourse.org/latest.json?page=1)

> [@Samir\_Sabri](#):
>
> how to restrict returned fields ? ex: I am getting all details currently.

您不能，您必须自己从结果中过滤掉它们。

> [@Samir\_Sabri](#):
>
> `?ascending=false`

这是默认设置，因此您无需指定 `ascending=false`，可以将其省略。

---

_[View the full topic](https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427)._
