Added on version 23.1.0b14
get_posts(self, starts_after: str = "", ends_before: str = "", sort_order: SORT_OPTION = "desc", limit: int = 20, author_id: str = "",) -> GetPublicPostsResponse:
Fetch a list of posts, can be filtered, ordered, and paginated.
author_id
: The ID of the user who authored the posts you want to retrieve.
sort_order
: Determines the order in which results are returned. Can be eitherasc
for ascending order ordesc
for descending order.
starts_after
: The ID of the post from which to start the query. This is useful for paginating results.
ends_before
: The ID of the post to end the query before. This is also useful for paginating results.
limit
: The maximum number of posts to retrieve per request.
Returns:
GetPublicRoomsResponse
: A list of public data of posts.
⚙️ Use cases
Here’s an example on how to get the last post from the user saying the command:
async def on_chat(self, user: User, message: str) -> None: if message.lower().startswith("/getpost"): author_id = user.id posts = await self.webapi.get_posts(author_id=author_id) last_post = posts.posts[0] print (last_post)
Response:
PostBasic( post_id='62b0d42156a97183fac3dfd2', author_id='6111e1fb22dcb50edf32e4a8', created_at='2022-06-20T20:10:09.476000+00:00', file_key='posts/6111e1fb22dcb50edf32e4a8/62b0d41f0a160174540ba611_0.webp', type='photo', visibility='public', num_comments=4, num_likes=3, num_reposts=0, body=PostBody( text='None', inventory=PostInventory(items=[])), caption='num dia desses comuns que eu não me sinto normal', featured_user_ids=[])