snoo
A Go client for the Reddit API. This package aims to implement every endpoint exposed according to the documentation in a user friendly.
Installation
Install the package with
go get -u github.com/mfdeux/snoo
Authentication
Many endpoints in the Reddit API require OAuth2 authentication to access. To get started, register an app at https://www.reddit.com/prefs/apps and be sure to note the ID, secret, and redirect URI. These values will be used to construct the Authenticator to generate a client with OAuth access. The following is an example of creating an authenticated client using a manual approach:
package main
import (
"fmt"
"github.com/mfdeux/snoo"
)
func main() {
authenticator := reddit.NewAuthenticator("<client_id>", "<client_secret>", "<redirect_uri>",
"<platform>:<app ID>:<version string> (by /u/<snoo username>)", "<random_string>", snoo.ScopeIdentity)
url := authenticator.GetAuthenticationURL()
fmt.Printf("Please proceed to %s\n", url)
fmt.Print("Enter state: ")
var state string
fmt.Scanln(&state)
fmt.Print("Enter code: ")
var code string
fmt.Scanln(&code)
token, err := authenticator.GetToken(state, code)
client := authenticator.GetAuthClient(token)
}
Examples
client := snoo.NoAuthClient
client.GetDefaultSubreddits()
client.GetHotLinks("news")