Reddit 0.0.0-beta

Reddit.NET is a .NET Standard library that provides easy access to the Reddit API with virtually no boilerplate code required.

This is a prerelease version of Reddit.
There is a newer version of this package available.
See the version list below for details.
Install-Package Reddit -Version 0.0.0-beta
dotnet add package Reddit --version 0.0.0-beta
<PackageReference Include="Reddit" Version="0.0.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Reddit --version 0.0.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
    ____             __     __ _  __      _   __ ______ ______
   / __ \ ___   ____/ /____/ /(_)/ /_    / | / // ____//_  __/
  / /_/ // _ \ / __  // __  // // __/   /  |/ // __/    / /   
 / _, _//  __// /_/ // /_/ // // /_ _  / /|  // /___   / /    
/_/ |_| \___/ \__,_/ \__,_//_/ \__/(_)/_/ |_//_____/  /_/     

Created by Kris Craig.

Overview

Reddit.NET is a .NET Standard library that provides easy access to the Reddit API with virtually no boilerplate code required. Keep reading below for code examples.

Currently, the library supports 169 of the 205 endpoints listed in the API documentation. All of them (except voting and admin-reporting, for obvious reasons) are covered by integration tests and all 327 of the tests are currently passing. All of the most commonly used endpoints are supported.

Reddit.NET is FOSS (MIT license) and was written in C#. It will be available on NuGet once I'm ready to put out the first stable release, which I expect to be very soon. You can check it out now on Github at:
https://github.com/sirkris/Reddit.NET/tree/develop

Contributors

Kris Craig, Andrew Hall, Ben Mitchell, Daryl Harrison, and the knowledgeable people over at r/csharp and r/redditdev.

Beta Testers

Kris Craig and Ben Mitchell.

Usage

Reddit.NET can be installed via NuGet. You can find it at: https://www.nuget.org/packages/Reddit

To install via the Visual Studio NuGet Package Manager Console (in VS 2017, you'll find it under Tools->NuGet Package Manager->NuGet Package Manager Console):

PM> Install-Package Reddit

To create a new API instance bound to a specific user's refresh token in an installed app:

using Reddit;

...

var reddit = new RedditAPI("YourRedditAppID", "YourBotUserRefreshToken");

If you're using a "script"-type app instead, you'll also need to pass your app secret:

using Reddit;

...

// You can also pass them as named parameters.
var reddit = new RedditAPI(appId: "YourRedditAppID", appSecret: "YourRedditAppSecret", refreshToken: "YourBotUserRefreshToken");

See below for more detailed usage examples.

Code Examples

using Reddit;
using Reddit.Controllers;
using Reddit.Controllers.EventArgs;
using System;

...

// Create a new Reddit.NET instance.
var r = new RedditAPI("MyAppID", "MyRefreshToken");

// Display the name and cake day of the authenticated user.
Console.WriteLine("Username: " + r.Account.Me.Name);
Console.WriteLine("Cake Day: " + r.Account.Me.Created.ToString("D"));

// Retrieve the authenticated user's recent post history.
// Change "new" to "newForced" if you don't want older stickied profile posts to appear first.
var postHistory = r.Account.Me.PostHistory(sort: "new");

// Retrieve the authenticated user's recent comment history.
var commentHistory = r.Account.Me.CommentHistory(sort: "new");

// Create a new subreddit.
var mySub = r.Subreddit("MyNewSubreddit", "My subreddit's title", "Description", "Sidebar").Create();

// Get info on another subreddit.
var askReddit = r.Subreddit("AskReddit").About();

// Get the top post from a subreddit.
var topPost = askReddit.Posts.Top[0];

// Create a new self post.
var mySelfPost = mySub.SelfPost("Self Post Title", "Self post text.").Submit();

// Create a new link post.
// Use .Submit(resubmit: true) instead to force resubmission of duplicate links.
var myLinkPost = mySub.LinkPost("Link Post Title", "http://www.google.com").Submit();  

// Comment on a post.
var myComment = myLinkPost.Reply("This is my comment.");

// Reply to a comment.
var myCommentReply = myComment.Reply("This is my comment reply.");

// Create a new subreddit, then create a new link post on said subreddit,
// then comment on said post, then reply to said comment, then delete said comment reply.
// Because I said so.
r.Subreddit("MySub", "Title", "Desc", "Sidebar")
.Create()
.SelfPost("MyPost")
.Submit()
.Reply("My comment.")
.Reply("This comment will be deleted.")
.Delete();

// Asynchronously monitor r/AskReddit for new posts.
askReddit.Posts.GetNew();
askReddit.Posts.NewUpdated += C_NewPostsUpdated;
askReddit.Posts.MonitorNew();

public static void C_NewPostsUpdated(object sender, PostsUpdateEventArgs e)
{
	foreach (var post in e.Added)
	{
		Console.WriteLine("New Post by " + post.Author + ": " + post.Title);
	}
}

// Stop monitoring r/AskReddit for new posts.
askReddit.Posts.MonitorNew();
askReddit.Posts.NewUpdated -= C_NewPostsUpdated;

Code Examples Using Models

The controllers basically just make calls to the models, which can be accessed directly via the Dispatch controller. As such, it is possible to bypass the controllers entirely for most things, so long as you don't mind the bulkier code. This is only recommended for scenarios where the convenience-oriented features of the controllers aren't needed and would just get in the way. In most cases, it is recommended that you instead use the controllers as demonstrated in the above examples.

Here's how you can do some basic things using the models:

using Reddit;
using Reddit.Inputs;
using Reddit.Inputs.LinksAndComments;
using Reddit.Inputs.Subreddits;
using Reddit.Inputs.Users;
using Reddit.Things;
using System;
using System.Collections.Generic;

...

// Create a new Reddit.NET instance.
var r = new RedditAPI("MyAppID", "MyRefreshToken");

// Display the name and cake day of the authenticated user.
Console.WriteLine("Username: " + r.Models.Account.Me().Name);
Console.WriteLine("Cake Day: " + r.Models.Account.Me().Created.ToString("D"));

// Retrieve the authenticated user's recent post history.
var postContainer = r.Models.Users.PostHistory(r.Models.Account.Me().Name, "overview", new UsersHistoryInput());
var postHistory = new List<Post>();
foreach (PostChild postChild in postContainer.JSON.Data.Things)
{
    if (postChild.Data != null)
    {
		postHistory.Add(postChild.Data);
    }
}

// Retrieve the authenticated user's recent comment history.
var commentContainer = r.Models.Users.CommentHistory(r.Models.Account.Me().Name, "comments", new UsersHistoryInput());
var commentHistory = new List<Comment>();
foreach (CommentChild commentChild in commentContainer.JSON.Data.Things)
{
    if (commentChild.Data != null)
    {
		commentHistory.Add(commentChild.Data);
    }
}

// Create a new subreddit.
r.Models.Subreddits.SiteAdmin(new SubredditsSiteAdminInput(name: "MyNewSubreddit", title: "My subreddit's title", publicDescription: "Description", description: "Sidebar"));
var mySub = r.Models.Subreddits.About("MyNewSubreddit");

// Get info on another subreddit.
var askReddit = r.Models.Subreddits.About("AskReddit");

// Get the top post from a subreddit.
var topPost = r.Models.Listings.Top(new TimedCatSrListingInput(), "AskReddit").JSON.Data.Things[0].Data;

// Create a new self post.
r.Models.LinksAndComments.Submit(new LinksAndCommentsSubmitInput(title: "Self Post Title", text: "Self post text."));

// Create a new link post.
r.Models.LinksAndComments.Submit(new LinksAndCommentsSubmitInput(title: "Link Post Title", url: "http://www.google.com"));

// Comment on a post.
r.Models.LinksAndComments.Comment(new LinksAndCommentsThingInput("This is my comment.", topPost.Name));

For more examples, check out the Example and Reddit.NETTests projects.

Full README

    ____             __     __ _  __      _   __ ______ ______
   / __ \ ___   ____/ /____/ /(_)/ /_    / | / // ____//_  __/
  / /_/ // _ \ / __  // __  // // __/   /  |/ // __/    / /   
 / _, _//  __// /_/ // /_/ // // /_ _  / /|  // /___   / /    
/_/ |_| \___/ \__,_/ \__,_//_/ \__/(_)/_/ |_//_____/  /_/     

Created by Kris Craig.

Overview

Reddit.NET is a .NET Standard library that provides easy access to the Reddit API with virtually no boilerplate code required. Keep reading below for code examples.

Currently, the library supports 169 of the 205 endpoints listed in the API documentation. All of them (except voting and admin-reporting, for obvious reasons) are covered by integration tests and all 327 of the tests are currently passing. All of the most commonly used endpoints are supported.

Reddit.NET is FOSS (MIT license) and was written in C#. It will be available on NuGet once I'm ready to put out the first stable release, which I expect to be very soon. You can check it out now on Github at:
https://github.com/sirkris/Reddit.NET/tree/develop

Contributors

Kris Craig, Andrew Hall, Ben Mitchell, Daryl Harrison, and the knowledgeable people over at r/csharp and r/redditdev.

Beta Testers

Kris Craig and Ben Mitchell.

Usage

Reddit.NET can be installed via NuGet. You can find it at: https://www.nuget.org/packages/Reddit

To install via the Visual Studio NuGet Package Manager Console (in VS 2017, you'll find it under Tools->NuGet Package Manager->NuGet Package Manager Console):

PM> Install-Package Reddit

To create a new API instance bound to a specific user's refresh token in an installed app:

using Reddit;

...

var reddit = new RedditAPI("YourRedditAppID", "YourBotUserRefreshToken");

If you're using a "script"-type app instead, you'll also need to pass your app secret:

using Reddit;

...

// You can also pass them as named parameters.
var reddit = new RedditAPI(appId: "YourRedditAppID", appSecret: "YourRedditAppSecret", refreshToken: "YourBotUserRefreshToken");

See below for more detailed usage examples.

Code Examples

using Reddit;
using Reddit.Controllers;
using Reddit.Controllers.EventArgs;
using System;

...

// Create a new Reddit.NET instance.
var r = new RedditAPI("MyAppID", "MyRefreshToken");

// Display the name and cake day of the authenticated user.
Console.WriteLine("Username: " + r.Account.Me.Name);
Console.WriteLine("Cake Day: " + r.Account.Me.Created.ToString("D"));

// Retrieve the authenticated user's recent post history.
// Change "new" to "newForced" if you don't want older stickied profile posts to appear first.
var postHistory = r.Account.Me.PostHistory(sort: "new");

// Retrieve the authenticated user's recent comment history.
var commentHistory = r.Account.Me.CommentHistory(sort: "new");

// Create a new subreddit.
var mySub = r.Subreddit("MyNewSubreddit", "My subreddit's title", "Description", "Sidebar").Create();

// Get info on another subreddit.
var askReddit = r.Subreddit("AskReddit").About();

// Get the top post from a subreddit.
var topPost = askReddit.Posts.Top[0];

// Create a new self post.
var mySelfPost = mySub.SelfPost("Self Post Title", "Self post text.").Submit();

// Create a new link post.
// Use .Submit(resubmit: true) instead to force resubmission of duplicate links.
var myLinkPost = mySub.LinkPost("Link Post Title", "http://www.google.com").Submit();  

// Comment on a post.
var myComment = myLinkPost.Reply("This is my comment.");

// Reply to a comment.
var myCommentReply = myComment.Reply("This is my comment reply.");

// Create a new subreddit, then create a new link post on said subreddit,
// then comment on said post, then reply to said comment, then delete said comment reply.
// Because I said so.
r.Subreddit("MySub", "Title", "Desc", "Sidebar")
.Create()
.SelfPost("MyPost")
.Submit()
.Reply("My comment.")
.Reply("This comment will be deleted.")
.Delete();

// Asynchronously monitor r/AskReddit for new posts.
askReddit.Posts.GetNew();
askReddit.Posts.NewUpdated += C_NewPostsUpdated;
askReddit.Posts.MonitorNew();

public static void C_NewPostsUpdated(object sender, PostsUpdateEventArgs e)
{
	foreach (var post in e.Added)
	{
		Console.WriteLine("New Post by " + post.Author + ": " + post.Title);
	}
}

// Stop monitoring r/AskReddit for new posts.
askReddit.Posts.MonitorNew();
askReddit.Posts.NewUpdated -= C_NewPostsUpdated;

Code Examples Using Models

The controllers basically just make calls to the models, which can be accessed directly via the Dispatch controller. As such, it is possible to bypass the controllers entirely for most things, so long as you don't mind the bulkier code. This is only recommended for scenarios where the convenience-oriented features of the controllers aren't needed and would just get in the way. In most cases, it is recommended that you instead use the controllers as demonstrated in the above examples.

Here's how you can do some basic things using the models:

using Reddit;
using Reddit.Inputs;
using Reddit.Inputs.LinksAndComments;
using Reddit.Inputs.Subreddits;
using Reddit.Inputs.Users;
using Reddit.Things;
using System;
using System.Collections.Generic;

...

// Create a new Reddit.NET instance.
var r = new RedditAPI("MyAppID", "MyRefreshToken");

// Display the name and cake day of the authenticated user.
Console.WriteLine("Username: " + r.Models.Account.Me().Name);
Console.WriteLine("Cake Day: " + r.Models.Account.Me().Created.ToString("D"));

// Retrieve the authenticated user's recent post history.
var postContainer = r.Models.Users.PostHistory(r.Models.Account.Me().Name, "overview", new UsersHistoryInput());
var postHistory = new List<Post>();
foreach (PostChild postChild in postContainer.JSON.Data.Things)
{
    if (postChild.Data != null)
    {
		postHistory.Add(postChild.Data);
    }
}

// Retrieve the authenticated user's recent comment history.
var commentContainer = r.Models.Users.CommentHistory(r.Models.Account.Me().Name, "comments", new UsersHistoryInput());
var commentHistory = new List<Comment>();
foreach (CommentChild commentChild in commentContainer.JSON.Data.Things)
{
    if (commentChild.Data != null)
    {
		commentHistory.Add(commentChild.Data);
    }
}

// Create a new subreddit.
r.Models.Subreddits.SiteAdmin(new SubredditsSiteAdminInput(name: "MyNewSubreddit", title: "My subreddit's title", publicDescription: "Description", description: "Sidebar"));
var mySub = r.Models.Subreddits.About("MyNewSubreddit");

// Get info on another subreddit.
var askReddit = r.Models.Subreddits.About("AskReddit");

// Get the top post from a subreddit.
var topPost = r.Models.Listings.Top(new TimedCatSrListingInput(), "AskReddit").JSON.Data.Things[0].Data;

// Create a new self post.
r.Models.LinksAndComments.Submit(new LinksAndCommentsSubmitInput(title: "Self Post Title", text: "Self post text."));

// Create a new link post.
r.Models.LinksAndComments.Submit(new LinksAndCommentsSubmitInput(title: "Link Post Title", url: "http://www.google.com"));

// Comment on a post.
r.Models.LinksAndComments.Comment(new LinksAndCommentsThingInput("This is my comment.", topPost.Name));

For more examples, check out the Example and Reddit.NETTests projects.

Full README

Release Notes

https://github.com/sirkris/Reddit.NET/blob/master/README.md

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Reddit:

Repository Stars
aelassas/Wexflow
An easy and fast way to build automation and workflows on Windows, Linux, macOS, and the cloud.

Version History

Version Downloads Last updated
1.4.0 6,533 2/24/2020
1.3.4 1,873 11/27/2019
1.3.0 165 11/25/2019
1.2.0 3,172 7/1/2019
1.1.1 1,346 3/19/2019
1.1.0 593 3/18/2019
1.0.0 1,147 2/11/2019
0.0.0-develop 585 1/21/2019
0.0.0-beta 555 1/30/2019
Show less