EDIT: Ohh you want latest posts, not latest topics. Considering /posts by itself doesn’t have a UI, it probably is missing pagination, I’m sure a PR could be created for this. But to get what you want right now you could still parse the /latest.json endpoint and parse out the topic_id and the post number and fetch the post with /t/<topic_id>/<post_number>, but yea I can see why pagination on the /posts endpoint would be helpful.
Okay, now that I’ve looked at the controller for /posts:
def latest
params.permit(:before)
...
there is a “before” parameter, not a “page” parameter, but using it like a “page” is a bit different because it filters out private posts and such. But I think roughly you can use it like this:
hit /posts.json and get the first post id (currently it is 22000)
subtract 50 (that endpoint only shows at most 50 at a time)
hit /posts.json?before=21950
repeat
Part of the issue which doesn’t make total sense to me is that we are limiting the sql query to 50 results, but then we do more filtering on it after the initial sql query which is why you will not always get 50 results.
as the API designer: it works this way to make things easier on the Discourse server; if the server had to do a bunch of work to always fill up 50 posts anything using the API might start being a perf problem.
Basically it forces the consumers to be “good neighbors”, in a weird sense of the term.
Pregunta sobre el uso de la API (¡que estoy utilizando a través del gem discourse_api, genial!) - está relacionada con la paginación (también me gustaría usar el endpoint de las últimas publicaciones), pero para mi ejemplo actual a continuación proporcionaré algo de usuarios, ya que comencé a trabajar en ello primero.
Quiero obtener toda la actividad de un usuario (temas y respuestas está bien), así que estoy intentando esto:
vsoch = client.user_topics_and_replies("vsoch")
Y luego consistentemente obtengo una lista de 30, independientemente de si el usuario obviamente tiene más. Intenté editar el código fuente para agregar una variable de página:
# frozen_string_literal: true
module DiscourseApi
module API
module UserActions
def user_replies(username, page=1)
params = { "username": username, "filter": '5', page: page }
response = get("/user_actions.json", params)
response.body["user_actions"]
end
def user_topics_and_replies(username, page=1)
params = { "username": username, "filter": "4,5", page: page }
response = get("/user_actions.json", params)
response.body["user_actions"]
end
end
end
end
pero parece que no hace nada; siempre es la misma lista de 30 independientemente del número de página. ¿Es posible obtener más de 30? ¿Estoy intentando algo incorrecto? Cualquier ayuda sería muy apreciada; si puedo averiguar cómo hacerlo, con mucho gusto enviaré una PR para que otros también puedan hacerlo