vartanbeno / go-reddit

Go library for accessing the Reddit API.
Other
304 stars 81 forks source link

403 Forbidden #36

Open Albinzr opened 2 years ago

Albinzr commented 2 years ago

When I tried, the bellow code i got 403 error, Can any one tell me why this is happening and how can I fix this issue?

        package main

        import (
            "context"
            "fmt"

            "github.com/vartanbeno/go-reddit/v2/reddit"
        )

        func main() {
            ctx := context.Background()
            client, err := reddit.NewReadonlyClient()

            if err != nil {
                fmt.Println("Error from reddit.NewReadonlyClient()", err)
            }
            listOpts := &reddit.ListOptions{
                Limit: 10, // always 100, so we can filter out without extra logic; if this is ever > 100, use resp.After
            }
            data, res, err := client.Subreddit.HotPosts(ctx, "AnimalsBeingBros", listOpts)

            fmt.Println(data)
            fmt.Println(res)
            fmt.Println(err)

        }
jancimertel commented 2 years ago

NewReadonlyClient being variadic, it accepts custom http client reference

Reddit api blocks the default http client configuration. Don't know when it started, but should be recently.

Edit: more here