Skip to content

Shiroechi/OpenTriviaSharp

Repository files navigation

OpenTriviaSharp

API wrapper for opentdb.com

CodeFactor

Download

Nuget

Feature

  • Get randon questions
  • Session token to prevent duplicate question

Example

Basic Usage

var client = new OpenTriviaClient();
var questions = await client.GetQuestionAsync(
    amount: 2, // number of question to retrieve ( 1 .. 50)
    type: TriviaType.Multiple, // question type (multiple choice or boolean)
    difficulty: Difficulty.Hard, // difficulty of the question (easy/medium/hard)
    category: Category.General); // category of the question

Using session token

// create Open triva client 
var client = new OpenTriviaClient();

// request the token
var token = await client.client.RequestTokenAsync();

var questions = await client.GetQuestionAsync(
    amount: 2, // number of question to retrieve ( 1 .. 50)
    type: TriviaType.Multiple, // question type (multiple choice or boolean)
    difficulty: Difficulty.Hard, // difficulty of the question (easy/medium/hard)
    category: Category.General, // category of the question
    sessionToken: token);  // prevent duplicate question

Every requested token only available for 6 hours, after that you must reset the token. If all question already retrieved with the token, you must reset it again or it will throw exception.

Reset token

var client = new OpenTriviaClient();

var token = await client.client.RequestTokenAsync();

await client.ResetTokenAsync(token);