Skip to main content Link Search Menu Expand Document (external link)

Getting started

Prerequisites

Installation

The Reddit.NET.Client assembly is available as a Nuget package.

You can use the Nuget package manager to install the package as follows:

PM> Install-Package Reddit.NET.Client -Version {Version}

Or directly add a PackageReference element to your project, if preferred:

<PackageReference Include="Reddit.NET.Client" Version="{Version}" />

Usage

To start interacting with reddit, the RedditClientBuilder class can be used to obtain a RedditClient instance.

The builder requires an IHttpClientFactory instance and ILoggerFactory instance to be provided, as well as an action for configuring the credentials used by the client:

using Reddit.NET.Client.Builder;

RedditClientBuilder builder = RedditClientBuilder.New;

// Configure builder
builder
    .WithHttpClientFactory(httpClientFactory)
    .WithLoggerFactory(loggerFactory)                
    .WithCredentialsConfiguration(credentialsBuilder => 
    {                    
        // Configure credentials
        credentialsBuilder.Script(
            clientId,
            clientSecret,
            username,
            password);        
    });

RedditClient client = await builder.BuildAsync();

An extension method is provided to configure a named HttpClient that the client will use for HTTP communication. This ensures that a unique and descriptive User-Agent is configured, as per the reddit API rules.

IServiceCollection services = ...;

services.AddRedditHttpClient(userAgent: "<platform>:<app ID>:<version string> (by /u/<reddit username>)");

Continue to the Concepts section for more details on the functionality provided by the RedditClient class.