vartanbeno / go-reddit

Go library for accessing the Reddit API.
Other
306 stars 84 forks source link

How do I get the header image for a post? #42

Open DaleEMoore opened 1 year ago

DaleEMoore commented 1 year ago

Howdy all y'all,

I'm trying to find and display a post's header image.

Is this a good place to look for it?

    posts, resp, err = cl.Subreddit.TopPosts(ctx, subreddit, &reddit.ListPostOptions{
        ListOptions: reddit.ListOptions{
            Limit: maxRedditItems,
            After: respAfter,
        },
        Time: "all",
    })

    var thePosts []*reddit.Post = nil
    for _, post := range posts {
        lastByByte := strings.ToLower(post.URL[len(post.URL)-4:])
        if (lastByByte == ".jpg") || (lastByByte == ".png") {
            log.Println("URL is an image:", post.URL)
        } else {
            log.Println("URL is NOT an image:", post.URL)
        }
        thePosts = append(thePosts, post)
    }

Thanks for any help! Dale

DaleEMoore commented 1 year ago

Is it a good assumption on my part to use:

log.Println("URL is an image:", post.URL)

as the post's image?