forked from vartanbeno/go-reddit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (46 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"context"
"fmt"
"log"
"github.com/vartanbeno/go-reddit/v2/reddit"
)
var ctx = context.Background()
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() (err error) {
// Let's get the top 200 posts of r/golang.
// Reddit returns a maximum of 100 posts at a time,
// so we'll need to separate this into 2 requests.
posts, resp, err := reddit.DefaultClient().Subreddit.TopPosts(ctx, "golang", &reddit.ListPostOptions{
ListOptions: reddit.ListOptions{
Limit: 100,
},
Time: "all",
})
if err != nil {
return
}
for _, post := range posts {
fmt.Println(post.Title)
}
// The After option sets the id of an item that Reddit
// will use as an anchor point for the returned listing.
posts, _, err = reddit.DefaultClient().Subreddit.TopPosts(ctx, "golang", &reddit.ListPostOptions{
ListOptions: reddit.ListOptions{
Limit: 100,
After: resp.After,
},
Time: "all",
})
if err != nil {
return
}
for _, post := range posts {
fmt.Println(post.Title)
}
return
}