2020-08-02 15:59:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2021-01-31 20:36:04 -05:00
|
|
|
"github.com/vartanbeno/go-reddit/v2/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) {
|
2021-01-24 22:51:27 -05:00
|
|
|
credentials := reddit.Credentials{ID: "id", Secret: "secret", Username: "username", Password: "password"}
|
|
|
|
client, err := reddit.NewClient(credentials)
|
2020-08-02 15:59:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-01 22:35:28 -04:00
|
|
|
post, _, err := client.Post.SubmitText(ctx, reddit.SubmitTextRequest{
|
2020-08-02 15:59:25 -04:00
|
|
|
Subreddit: "test",
|
|
|
|
Title: "This is a title",
|
|
|
|
Text: "This is some text",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("The text post is available at: %s\n", post.URL)
|
|
|
|
|
2020-09-01 22:35:28 -04:00
|
|
|
post, _, err = client.Post.SubmitLink(ctx, reddit.SubmitLinkRequest{
|
2020-08-02 15:59:25 -04:00
|
|
|
Subreddit: "test",
|
|
|
|
Title: "This is a title",
|
|
|
|
URL: "http://example.com",
|
|
|
|
Resubmit: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("The link post is available at: %s\n", post.URL)
|
|
|
|
return
|
|
|
|
}
|