turnage / graw

Golang Reddit API Wrapper
MIT License
288 stars 49 forks source link

The Thread method isn't returning the fully parsed comment tree. #90

Open krishamoud opened 2 years ago

krishamoud commented 2 years ago

Maybe I'm doing something wrong but after going through the documentation and trying to figure out what's happening I'm not sure what I'm doing wrong.

The simplest reproduction of it is this.

package main

import (
    "fmt"

    "github.com/turnage/graw/reddit"
)

func main() {
    if bot, err := reddit.NewBotFromAgentFile("some-app.agent", 0); err != nil {
        fmt.Println("Failed to create bot handle: ", err)
    } else {
        thread, err := bot.Thread("/r/golang/comments/bv0azt/using_graw_a_reddit_api_wrapper_for_go_like_praw/")
        if err != nil {
            fmt.Println(err)
        }
        for _, comment := range thread.Replies {
            fmt.Println(comment.Body)
        }
    }
}

Which outputs

⇒  go run main.go
Did this get resolved? I'm having the same problem.

And it should have three comments unless I'm misunderstanding something.

link to the reddit thread in question

Thanks in advance! I feel like I'm missing something silly.

dnapier commented 2 years ago

Your loop needs expanding

for _, comment := range thread.Replies {
    for _, v := range comment.Replies {
        fmt.Println(v)
    }
}