All Projects → vartanbeno → Go Reddit

vartanbeno / Go Reddit

Licence: other
Go library for accessing the Reddit API.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Reddit

Docs
API Platform documentation
Stars: ✭ 119 (-32%)
Mutual labels:  api, hacktoberfest
Mailcare
[MIRRORING REPOSITORY] See https://gitlab.com/mailcare/mailcare. MailCare is an open source disposable email address services. Accessible via web browser or API to protect your privacy right now.
Stars: ✭ 136 (-22.29%)
Mutual labels:  api, hacktoberfest
Water Monitoring System
Water Monitoring System is an IOT based Liquid Level Monitoring system that has mechanisms to keep the user alerted in case of liquid overflow or when tank depletes.
Stars: ✭ 122 (-30.29%)
Mutual labels:  api, hacktoberfest
Blinkpy
A Python library for the Blink Camera system
Stars: ✭ 174 (-0.57%)
Mutual labels:  api, hacktoberfest
Brain.js
brain.js is a GPU accelerated library for Neural Networks written in JavaScript.
Stars: ✭ 12,358 (+6961.71%)
Mutual labels:  api, hacktoberfest
Laravel Api Boilerplate
A Boilerplate Project For Laravel API's (NOT MAINTAINED)
Stars: ✭ 113 (-35.43%)
Mutual labels:  api, hacktoberfest
Reddit Detective
Play detective on Reddit: Discover political disinformation campaigns, secret influencers and more
Stars: ✭ 129 (-26.29%)
Mutual labels:  api, reddit
Swagger Combine
Combines multiple Swagger schemas into one dereferenced schema.
Stars: ✭ 102 (-41.71%)
Mutual labels:  api, hacktoberfest
Core
The server component of API Platform: hypermedia and GraphQL APIs in minutes
Stars: ✭ 2,004 (+1045.14%)
Mutual labels:  api, hacktoberfest
Smoke
💨 Simple yet powerful file-based mock server with recording abilities
Stars: ✭ 142 (-18.86%)
Mutual labels:  api, hacktoberfest
Neovim
Vim-fork focused on extensibility and usability
Stars: ✭ 49,389 (+28122.29%)
Mutual labels:  api, hacktoberfest
Whatsapp Web.js
A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
Stars: ✭ 4,103 (+2244.57%)
Mutual labels:  api, hacktoberfest
Strapi
🚀 Open source Node.js Headless CMS to easily build customisable APIs
Stars: ✭ 41,786 (+23777.71%)
Mutual labels:  api, hacktoberfest
Python Gitlab
Python wrapper for the GitLab API
Stars: ✭ 1,679 (+859.43%)
Mutual labels:  api, hacktoberfest
Ex gram
Telegram Bot API low level API and framework
Stars: ✭ 103 (-41.14%)
Mutual labels:  api, hacktoberfest
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-30.86%)
Mutual labels:  api, hacktoberfest
Tutorialdb
A search 🔎 engine for programming/dev tutorials, See it in action 👉
Stars: ✭ 93 (-46.86%)
Mutual labels:  api, hacktoberfest
Finmind
Open Data, more than 50 financial data. 提供超過 50 個金融資料(台股為主),每天更新 https://finmind.github.io/
Stars: ✭ 1,357 (+675.43%)
Mutual labels:  api, hacktoberfest
Bandcamp Scraper
A scraper for https://bandcamp.com
Stars: ✭ 137 (-21.71%)
Mutual labels:  api, hacktoberfest
Sampleapis
This repository is a playground for API's. These are just a collection of items that you can utilize for learning purposes.
Stars: ✭ 157 (-10.29%)
Mutual labels:  api, hacktoberfest

go-reddit logo

Actions Status Go Report Card PkgGoDev

Overview

Featured in issues 327 and 347 of Golang Weekly 🎉

go-reddit is a Go client library for accessing the Reddit API.

You can view Reddit's official API documentation here.

Install

To get a specific version from the list of versions:

go get github.com/vartanbeno/go-reddit/[email protected]

Or for the latest version:

go get github.com/vartanbeno/go-reddit/v2

The repository structure for managing multiple major versions follows the one outlined here.

Usage

Make sure to have a Reddit app with a valid client id and secret. Here is a quick guide on how to create an app and get credentials.

package main

import "github.com/vartanbeno/go-reddit/v2/reddit"

func main() {
    credentials := reddit.Credentials{ID: "id", Secret: "secret", Username: "username", Password: "password"}
    client, _ := reddit.NewClient(credentials)
}

You can pass in a number of options to NewClient to further configure the client (see reddit/reddit-options.go). For example, to use a custom HTTP client:

httpClient := &http.Client{Timeout: time.Second * 30}
client, _ := reddit.NewClient(credentials, reddit.WithHTTPClient(httpClient))

Read-Only Mode

The DefaultClient method returns a valid, read-only client with limited access to the Reddit API, much like a logged out user. You can initialize your own and configure it further using options via NewReadonlyClient:

client, _ := reddit.NewReadonlyClient()

Examples

Configure the client from environment variables. When using this option, it's ok to pass an empty struct for the credentials.
client, _ := reddit.NewClient(reddit.Credentials{}, reddit.FromEnv)
Submit a comment.
comment, _, err := client.Comment.Submit(context.Background(), "t3_postid", "comment body")
if err != nil {
    return err
}
fmt.Printf("Comment permalink: %s\n", comment.Permalink)
Upvote a post.
_, err := client.Post.Upvote(context.Background(), "t3_postid")
if err != nil {
    return err
}
Get r/golang's top 5 posts of all time.
posts, _, err := client.Subreddit.TopPosts(context.Background(), "golang", &reddit.ListPostOptions{
    ListOptions: reddit.ListOptions{
        Limit: 5,
    },
    Time: "all",
})
if err != nil {
    return err
}
fmt.Printf("Received %d posts.\n", len(posts))

More examples are available in the examples folder.

Design

The package design is heavily inspired from Google's GitHub API client and DigitalOcean's API client.

Contributing

Contributions are welcome! For any bug reports/feature requests, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].