this post was submitted on 30 Jun 2023
4 points (100.0% liked)

Lemmy App Development

762 readers
8 users here now

A place for Lemmy builders to chat about building apps, clients, tools and bots for the Lemmy platform.

On-Topic:

Off-Topic:

founded 2 years ago
MODERATORS
 

Sometimes an API request returns {"comments":[]} and {"posts":[]} respectively, for a post and community, where posts and comments show up on the web frontend. Is that happening to any of you too? How do I handle it?

Edit: did some more testing, it's most definitely a federation issue. If I query the instance that the post was made on for the comments, everything works fine. If I query my home instance, the result comes back empty.

Edit 2: As always, just after publicly showcasing my lack of programming abilities, I discover it's been me the entire time. Make sure to await promises and to fetch posts from the correct instance, guys.

top 8 comments
sorted by: hot top controversial new old
[–] RoundSparrow@lemmy.ml 4 points 2 years ago* (last edited 2 years ago)

Edit: did some more testing, it’s most definitely a federation issue. If I query the instance that the post was made on for the comments, everything works fine.

Oh, I ran into that. There is a post on !lemmycode@lemmy.ml even.

You need to set the type_=All on fetching comments for a community that isn't originated on your local server. You can just use that parameter when fetching comments from any post.

[–] nmtake@lemm.ee 3 points 2 years ago (1 children)
[–] HerrLewakaas@feddit.de 1 points 2 years ago

Pretty sure it didn't work, but I can't replicate it right now. Will need to see if it happens again

[–] RoundSparrow@lemmy.ml 2 points 2 years ago (1 children)

I've had lemmy_helper crawling posts looking for missing comments for the same post on different servers, thousands of posts, and I haven't seen this yet. Lemmy.ml is the most unstable server - it ever returns an HTTP status problem or some error message.

[–] HerrLewakaas@feddit.de 1 points 2 years ago* (last edited 2 years ago) (1 children)

To be clear, I checked twice that my limit and page parameters are correct. I request page 0 with limit 10 and get nothing, while the post counts clearly say there are multiple comments and while the web interface shows them normally. Very weird

[–] RoundSparrow@lemmy.ml 2 points 2 years ago* (last edited 2 years ago) (1 children)

I request page 0 with limit 10 and get nothing

Lemmy API starts at page 1, page 0 is invalid?

curl "https://lemmy.ca/api/v3/post/list?limit=2&page=1"
curl "https://lemmy.ca/api/v3/comment/list?post_id=648889&type_=All&limit=2&page=1"

page=0 returns {"error":"couldnt_get_posts"} (or comments)

[–] HerrLewakaas@feddit.de 2 points 2 years ago

I meant page 1, sorry

[–] silas@programming.dev 2 points 2 years ago

Lol, I was gonna say I’ve never experienced this before

load more comments
view more: next ›