Skip to content
A .NET library for the Trakt.tv API.
Branch: develop
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Replace "TraktApiSharp" with "Trakt.NET" int issue template Jun 27, 2018
Source Merge branch 'release-1.0.0' into merge/develop/GH-120 May 5, 2019
.gitattributes Initial commit. Mar 31, 2016
.gitignore Exclude jekyll output folder from version control Dec 18, 2016
AUTHORS.md
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md May 14, 2018
CONTRIBUTING.md Update contribution guidelines Jun 26, 2018
Changelog.md Update changelog Mar 30, 2019
LICENSE.md Update copyright year Jan 14, 2019
PublishRelease.txt GH-14: Replace all occurences of "TraktApiSharp" with "Trakt.NET" in … Jun 26, 2018
README.md Update readme Apr 1, 2019
coding_style.md GH-14: Replace all occurences of "TraktApiSharp" with "Trakt.NET" in … Jun 26, 2018

README.md

Trakt.NET TwitterTwitter Follow

Formerly known as TraktApiSharp.

This is a .NET wrapper library for the Trakt.tv API.

NuGet Package License PRs Welcome Quality Gate Status

Features

  • Full Trakt.tv API Coverage
  • Authentication Support (OAuth 2.0 and Device)
  • Completely asynchronous
  • API Environments (Production and Sandbox)
  • Serialization Service
  • Language Service

Supported Platforms

  • .Net Core >= 1.0
  • .Net Framework >= 4.5
  • Mono >= 4.6
  • Xamarin.iOS >= 10.0
  • Xamarin.Mac >= 3.0
  • Xamarin.Android >= 7.0
  • Windows UWP >= 10.0
  • Windows >= 8.0
  • Windows Phone >= 8.1

Chat Room

Do you have a question or suggestion?

Gitter

Or do you want to report a bug?

Contributions are welcome

Build Status

Branch Status Description
develop Build status This branch tracks the current and possibly unstable development.
release Build status This branch tracks the current development of the next upcoming release.

Getting Started

Install the latest release by running the following NuGet command

PM> Install-Package Trakt.NET

or with the NuGet Package Management in Visual Studio and search for "trakt".

Each release will also be published in Releases.

You can also use one of the following NuGet Package Sources, to always get the latest build package.

NuGet-Feed Package Source Address Description
MyGet https://www.myget.org/F/trakt-net/api/v3/index.json All CI/CD build packages.

Basic Usage

Create a new Trakt.NET Client

// Client ID is sufficient for usage without OAuth
var client = new TraktClient("Your Trakt Client ID");

// Both Client ID and Client Secret are required, if you need to authenticate your application
var client = new TraktClient("Your Trakt Client ID", "Your Trakt Client Secret");

// Both Client ID and Access Token are required, if you want to use requests, that require authorization
var client = new TraktClient("Your Trakt Client ID")
{
    Authorization = TraktAuthorization.CreateWith("Trakt Access Token")
};

Use your existing tokens

var client = new TraktClient("Your Trakt Client ID");

// Only access token
client.Authorization = TraktAuthorization.CreateWith("Your Access Token");

// Access Token and Refresh Token
client.Authorization = TraktAuthorization.CreateWith("Your Access Token", "Your Refresh Token");

Serialize and deserialize authorization information

ITraktAuthorization authorization = client.Authorization;

// Get JSON string from current authorization
string json = await TraktSerializationService.SerializeAsync(authorization);

// Get TraktAuthorization from JSON string
ITraktAuthorization deserializedAuthorization = await TraktSerializationService.DeserializeAsync(json);

client.Authorization = deserializedAuthorization;

// authorization == deserializedAuthorization

Configure the client

client.ClientId = "Your Trakt Client ID";
client.ClientSecret = "Your Trakt Client Secret";

client.Configuration.ApiVersion = 2; // Set by default

// Set this to true, to use Trakt API staging environment
// This is disabled by default
client.Configuration.UseSandboxEnvironment = true;

// Force authorization for requests, where authorization is optional
// This is disabled by default
client.Configuration.ForceAuthorization = true;

Get the top 10 trending shows including full information

TraktPagedResponse<ITraktTrendingShow> trendingShowsTop10 = await client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo().SetFull(), null, 10);
// or
TraktPagedResponse<ITraktTrendingShow> trendingShowsTop10 = await client.Shows.GetTrendingShowsAsync(new TraktExtendedInfo() { Full = true }, 1, 10);

if (trendingShowsTop10)
{
    foreach (ITraktTrendingShow trendingShow in trendingShowsTop10)
    {
        Console.WriteLine($"Show: {trendingShow.Title} / Watchers: {trendingShow.Watchers}");
    }
}

Get the top 10 trending movies including full information

var extendedInfo = new TraktExtendedInfo() { Full = true };

TraktPagedResponse<ITraktTrendingMovie> trendingMoviesTop10 = await client.Movies.GetTrendingMoviesAsync(extendedInfo, null, 10);
// or
TraktPagedResponse<ITraktTrendingMovie> trendingMoviesTop10 = await client.Movies.GetTrendingMoviesAsync(extendedInfo, 1, 10);

if (trendingMoviesTop10)
{
    foreach (ITraktTrendingMovie trendingMovie in trendingMoviesTop10)
    {
        Console.WriteLine($"Movie: {trendingMovie.Title} / Watchers: {trendingMovie.Watchers}");
    }
}

Get the show 'Game of Thrones'

TraktResponse<ITraktShow> gameOfThrones = await client.Shows.GetShowAsync("game-of-thrones", new TraktExtendedInfo().SetFull());

if (gameOfThrones)
{
    ITraktShow show = gameOfThrones.Value;
    Console.WriteLine($"Title: {show.Title} / Year: {show.Year}");
    Console.WriteLine(show.Overview);
}

Get the movie 'The Martian'

TraktResponse<ITraktMovie> theMartian = await client.Movies.GetMovieAsync("the-martian-2015", new TraktExtendedInfo().SetFull());

if (theMartian)
{
    ITraktMovie movie = theMartian.Value;
    Console.WriteLine($"Title: {movie.Title} / Year: {movie.Year}");
    Console.WriteLine(show.Overview);
}

License

The MIT License (MIT)

Copyright © 2016 - 2019 Henrik Fröhling et al.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You can’t perform that action at this time.