{"id":13604695,"url":"https://github.com/vartanbeno/go-reddit","last_synced_at":"2025-04-12T02:31:19.241Z","repository":{"id":42680833,"uuid":"258360731","full_name":"vartanbeno/go-reddit","owner":"vartanbeno","description":"Go library for accessing the Reddit API.","archived":false,"fork":false,"pushed_at":"2024-03-15T11:30:24.000Z","size":836,"stargazers_count":311,"open_issues_count":24,"forks_count":85,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-05T09:06:43.966Z","etag":null,"topics":["api","go","golang","hacktoberfest","reddit"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vartanbeno.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-24T00:06:01.000Z","updated_at":"2024-10-31T08:28:37.000Z","dependencies_parsed_at":"2024-01-07T05:59:52.793Z","dependency_job_id":"f7a9ddb1-9b77-4e06-8d92-9b5b3f9e53a1","html_url":"https://github.com/vartanbeno/go-reddit","commit_stats":{"total_commits":205,"total_committers":2,"mean_commits":102.5,"dds":0.004878048780487809,"last_synced_commit":"2f1019d1706b7de7188533ee8492a6613d05cd2c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vartanbeno%2Fgo-reddit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vartanbeno%2Fgo-reddit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vartanbeno%2Fgo-reddit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vartanbeno%2Fgo-reddit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vartanbeno","download_url":"https://codeload.github.com/vartanbeno/go-reddit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223489621,"owners_count":17153789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","go","golang","hacktoberfest","reddit"],"created_at":"2024-08-01T19:00:50.193Z","updated_at":"2024-11-07T09:30:44.541Z","avatar_url":"https://github.com/vartanbeno.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003cdiv align='center'\u003e\n\u003cbr /\u003e\n\u003cimg src='./images/logo.png' alt='go-reddit logo' height='150'\u003e\n\n---\n\n\u003cdiv id='badges' align='center'\u003e\n\n[![Actions Status](https://github.com/vartanbeno/go-reddit/workflows/tests/badge.svg)](https://github.com/vartanbeno/go-reddit/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/vartanbeno/go-reddit)](https://goreportcard.com/report/github.com/vartanbeno/go-reddit)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/vartanbeno/go-reddit/v2/reddit)](https://pkg.go.dev/github.com/vartanbeno/go-reddit/v2/reddit)\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n\n## Overview\n\n**Featured in issues [327](https://golangweekly.com/issues/327) and [347](https://golangweekly.com/issues/347) of Golang Weekly 🎉**\n\ngo-reddit is a Go client library for accessing the Reddit API.\n\nYou can view Reddit's official API documentation [here](https://www.reddit.com/dev/api/).\n\n## Install\n\nTo get a specific version from the list of [versions](https://github.com/vartanbeno/go-reddit/releases):\n\n```sh\ngo get github.com/vartanbeno/go-reddit/v2@vX.Y.Z\n```\n\nOr for the latest version:\n\n```sh\ngo get github.com/vartanbeno/go-reddit/v2\n```\n\nThe repository structure for managing multiple major versions follows the one outlined [here](https://github.com/go-modules-by-example/index/tree/master/016_major_version_repo_strategy#major-branch-strategy).\n\n## Usage\n\nMake sure to have a Reddit app with a valid client id and secret. [Here](https://github.com/reddit-archive/reddit/wiki/OAuth2-Quick-Start-Example#first-steps) is a quick guide on how to create an app and get credentials.\n\n```go\npackage main\n\nimport \"github.com/vartanbeno/go-reddit/v2/reddit\"\n\nfunc main() {\n    credentials := reddit.Credentials{ID: \"id\", Secret: \"secret\", Username: \"username\", Password: \"password\"}\n    client, _ := reddit.NewClient(credentials)\n}\n```\n\nYou can pass in a number of options to `NewClient` to further configure the client (see [reddit/reddit-options.go](reddit/reddit-options.go)). For example, to use a custom HTTP client:\n\n```go\nhttpClient := \u0026http.Client{Timeout: time.Second * 30}\nclient, _ := reddit.NewClient(credentials, reddit.WithHTTPClient(httpClient))\n```\n\n### Read-Only Mode\n\nThe `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`:\n\n```go\nclient, _ := reddit.NewReadonlyClient()\n```\n\n## Examples\n\n\u003cdetails\u003e\n    \u003csummary\u003eConfigure the client from environment variables. When using this option, it's ok to pass an empty struct for the credentials.\u003c/summary\u003e\n\n```go\nclient, _ := reddit.NewClient(reddit.Credentials{}, reddit.FromEnv)\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eSubmit a comment.\u003c/summary\u003e\n\n```go\ncomment, _, err := client.Comment.Submit(context.Background(), \"t3_postid\", \"comment body\")\nif err != nil {\n    return err\n}\nfmt.Printf(\"Comment permalink: %s\\n\", comment.Permalink)\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eUpvote a post.\u003c/summary\u003e\n\n```go\n_, err := client.Post.Upvote(context.Background(), \"t3_postid\")\nif err != nil {\n    return err\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eGet r/golang's top 5 posts of all time.\u003c/summary\u003e\n\n```go\nposts, _, err := client.Subreddit.TopPosts(context.Background(), \"golang\", \u0026reddit.ListPostOptions{\n    ListOptions: reddit.ListOptions{\n        Limit: 5,\n    },\n    Time: \"all\",\n})\nif err != nil {\n    return err\n}\nfmt.Printf(\"Received %d posts.\\n\", len(posts))\n```\n\u003c/details\u003e\n\nMore examples are available in the [examples](examples) folder.\n\n## Design\n\nThe package design is heavily inspired from [Google's GitHub API client](https://github.com/google/go-github) and [DigitalOcean's API client](https://github.com/digitalocean/godo).\n\n## Contributing\n\nContributions are welcome! For any bug reports/feature requests, feel free to open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvartanbeno%2Fgo-reddit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvartanbeno%2Fgo-reddit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvartanbeno%2Fgo-reddit/lists"}