Acho que este é um bug recente que surgiu. Meu cliente usa o Discourse como serviço hospedado pela equipe maravilhosa do Discourse. Utilizamos o endpoint de API /posts.json para listar as 5 postagens mais recentes do fórum no site (https://forum.bonsaimirai.com/posts.json). Fazemos essa solicitação no lado do servidor usando curl.
Recentemente, notamos que só estávamos vendo 3 ou 4 das postagens mais recentes em nosso site. Parece que, quando a solicitação é feita sem uma chave de API, acabamos recebendo essa lista muito curta de postagens recentes. Mas, ao usar a chave de API com um nome de usuário de API, vemos um número maior de postagens.
Queremos que o endpoint /posts.json se comporte como antes. Devemos ser capazes de obter qualquer número de postagens anteriores que ele costumava entregar. Se usarmos a chave de API + nome de usuário, acabamos recuperando postagens que não queremos mostrar a todos os usuários (de categorias com restrições de nível de usuário/grupo).
Existem novos parâmetros disponíveis para a solicitação posts.json que podemos usar para especificar o número desejado de resultados? Isso é um bug exclusivo de alguma versão do Discourse usada no serviço hospedado? Notei que o meta.discourse.org não apresenta esse problema.
That implies you may have special security that keeps some of the posts from being visible to anonymous users?
@codinghorror I think I just realized why this is happening. We do have a category on our forum that is restricted to a special group of paying users on our main site. Anonymous / “normal” logged in users can’t access this category.
I’m going to guess that if a single topic in that special category contains some large number of the most recent posts to the site, then they’re simply omitted from the posts.json endpoint for anonymous users. And thus, we exceed whatever the behind-the-scenes limit is for that endpoint. So we end up getting the truncated list that I’m seeing in this specific moment in time when requesting that feed anonymously.
Am I on to something here?
This is probably an edge case. But does it make sense to make a feature request for that endpoint so that it always returns the X number of most recent posts, relevant to whatever level of permissions the request is being made from?
That feature already exists, include the API key of a user with the desired permissions.
Thanks @codinghorror.
This is exactly what I’ve done. I make a request for the /posts.json using my API key with a “dummy” user possessing the desired permissions since not all members of our website have created accounts on the forum yet.
Everything is working as expected.