# README
go-reddit
A Golang wrapper for the Reddit API. This package aims to implement every endpoint exposed according to the documentation in a user friendly, well tested and documented manner.
Installation
Install the package with
go get github.com/cameronstanley/go-reddit
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/cameronstanley/go-reddit"
)
func main() {
// Create a new authenticator with your app's client ID, secret, and redirect URI
// A random string representing state and a list of requested OAuth scopes are required
authenticator := reddit.NewAuthenticator("<client_id>", "<client_secret>", "<redirect_uri>", "<random_string>", reddit.ScopeIdentity)
// Instruct your user to visit the URL retrieved from GetAuthenticationURL in their web browser
url := authenticator.GetAuthenticationURL()
fmt.Printf("Please proceed to %s\n", url)
// After the user grants permission for your client, they will be redirected to the supplied redirect_uri with a code and state as URL parameters
// Gather these values from the user on the console
// Note: this can be automated by having a web server listen on the redirect_uri and parsing the state and code params
fmt.Print("Enter state: ")
var state string
fmt.Scanln(&state)
fmt.Print("Enter code: ")
var code string
fmt.Scanln(&code)
// Exchange the code for an access token
token, err := authenticator.GetToken(state, code)
// Create a new client using the access token and a user agent string to identify your application
client := authenticator.GetAuthClient(token, "<platform>:<app ID>:<version string> (by /u/<reddit username>)")
}
Examples
// Returns a new unauthenticated client for invoking the API
client := reddit.NoAuthClient
// Retrives a listing of default subreddits
client.GetDefaultSubreddits()
// Retrives a listing of hot links for the "news" subreddit
client.GetHotLinks("news")
# Functions
NewAuthenticator generates a new authenticator with the supplied client, state, and requested scopes.
No description provided by the author
# Constants
ScopeEdit allows modification and deletion of comments and submissions.
ScopeFlair allows modification of user link flair on submissions.
ScopeHistory allows access to user voting history on comments and submissions.
ScopeIdentity allows access to account information.
ScopeModConfig allows management of configuration, sidebar, and CSS of user managed subreddits.
ScopeModFlair allows management and assignment of user moderated subreddits.
ScopeModLog allows access to moderation log for user moderated subreddits.
ScopeModWiki allows changing of editors and visibility of wiki pages in user moderated subreddits.
ScopeMySubreddits allows access to the list of subreddits user moderates, contributes to, and is subscribed to.
ScopePrivateMessages allows access to user inbox and the sending of private messages to other users.
ScopeRead allows access to user posts and comments.
ScopeReport allows reporting of content for rules violations.
ScopeSave allows saving and unsaving of user comments and submissions.
ScopeSubmit allows user submission of links and comments.
ScopeSubscribe allows management of user subreddit subscriptions and friends.
ScopeVote allows user submission and changing of votes on comments and submissions.
ScopeWikiEdit allows user editing of wiki pages.
ScopeWikiRead allow user viewing of wiki pages.
# Variables
NoAuthClient is the unauthenticated client for interacting with the Reddit API.
# Structs
Account contains user account information.
Authenticator provides functions for authenticating a user via OAuth2 and generating a client that can be used to access authorized API endpoints.
No description provided by the author
Client is the client for interacting with the Reddit API.
Comment is a response to a link or another comment.
No description provided by the author
Link contains information about a link.
Media is a media content item.
Message is a private message between users.
Oembed contains embedding information for a media item.
Preferences contains a user's account preferences.
Subreddit contains subreddit information.