Skip to content

sridharv/reddit-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal Reddit API wrapper for Go.

This is a work in progress and may contain bugs. It has only been tested for the top posts query.

The GoDoc contains detailed documentation. The package examples contain details on how to use the package.

Please read the reddit API documentation first before reading these docs. Some useful links are:

This currently only supports OAuth for script apps. It does not support refreshing OAuth tokens. It provides the following:

  • Code to save and load authorization credentials (client id, client secret, etc).
  • A simple API to obtain and store an OAuth token for a script app using these credentials.
  • An API to perform GET requests using the obtained token.
  • An API to stream listings.

Example Usage

cfg, err := reddit.LoadConfig(reddit.DefaultConfigFile)
if err != nil {
    log.Fatal(err)
}
if err := cfg.AuthScript(http.DefaultClient); err != nil {
    log.Fatal(err)
}
// Print top posts of the day from /r/golang
stream := cfg.Stream(http.DefaultClient, &reddit.TopPosts{SubReddit: "golang", Duration: reddit.TopDay})
for stream.Next() {
    thing := stream.Thing()
    link := thing.Data.(*reddit.Link)
    fmt.Println(link.Title, link.URL)
}
if err := stream.Error(); err != nil {
    log.Fatal(err)
}

About

Minimal Reddit API Client in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages