2020-08-02 15:59:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2020-08-20 14:37:59 -04:00
|
|
|
"github.com/vartanbeno/go-reddit/reddit"
|
2020-08-02 15:59:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var ctx = context.Background()
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run() (err error) {
|
2020-08-23 22:25:29 -04:00
|
|
|
credentials := &reddit.Credentials{
|
|
|
|
ID: "id",
|
|
|
|
Secret: "secret",
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
}
|
2020-08-02 15:59:25 -04:00
|
|
|
|
2020-08-26 23:13:34 -04:00
|
|
|
client, err := reddit.NewClient(credentials)
|
2020-08-02 15:59:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
client.OnRequestCompleted(logResponse)
|
|
|
|
|
2020-08-05 13:25:09 -04:00
|
|
|
client.Subreddit.Search(ctx, "programming", nil)
|
2020-08-02 15:59:25 -04:00
|
|
|
client.Subreddit.SearchNames(ctx, "monitor")
|
2020-08-05 13:25:09 -04:00
|
|
|
client.Subreddit.SearchPosts(ctx, "react", "webdev", nil)
|
|
|
|
client.User.Posts(ctx, &reddit.ListUserOverviewOptions{
|
|
|
|
ListOptions: reddit.ListOptions{
|
|
|
|
Limit: 50,
|
|
|
|
},
|
|
|
|
Sort: "top",
|
|
|
|
Time: "month",
|
|
|
|
})
|
2020-08-02 15:59:25 -04:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func logResponse(req *http.Request, res *http.Response) {
|
|
|
|
fmt.Printf("%s %s %s\n", req.Method, req.URL, res.Status)
|
|
|
|
}
|