Socket
Socket
Sign inDemoInstall

github.com/sridharv/reddit-go

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/sridharv/reddit-go

Package reddit provides wrappers to the Reddit API for Go. 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: Please see the package examples for details on how to use the above functionality.


Version published

Readme

Source

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)
}

FAQs

Last updated on 18 Aug 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc