Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.68 KB

README.md

File metadata and controls

56 lines (38 loc) · 1.68 KB

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);