Skip to content

Repository files navigation

Pastebin API for C#

NugetNuget

This is a simple library for accessing Pastebin from C#

Example

usingSystem;usingSystem.Threading.Tasks;usingPastebinAPI;namespaceExample{classExample{staticvoidMain(){PastebinExample().GetAwaiter().GetResult();}staticasyncTaskPastebinExample(){//before using any class in the api you must enter your api dev keyPastebin.DevKey="your dev key goes here";//you can see yours here: https://pastebin.com/api#1try{// login and get user objectUserme=awaitPastebin.LoginAsync("user","pass");// user contains information like e-mail, location etc...Console.WriteLine("{0}({1}) lives in {2}",me,me.Email,me.Location);// lists all pastes for this userforeach(Pastepasteinawaitme.ListPastesAsync(3))// we limmit the results to 3{Console.WriteLine(paste.Title);}stringcode="<your fancy &code#() goes here>";//creates a new paste and get paste objectPastenewPaste=awaitme.CreatePasteAsync(code,"MyPasteTitle",Language.HTML5,Visibility.Public,Expiration.TenMinutes);//newPaste now contains the link returned from the serverConsole.WriteLine("URL: {0}",newPaste.Url);Console.WriteLine("Paste key: {0}",newPaste.Key);Console.WriteLine("Content: {0}",newPaste.Text);//deletes the paste we just createdawaitme.DeletePasteAsync(newPaste);//lists all currently trending pastes(similar to me.ListPastes())foreach(PastepasteinawaitPastebin.ListTrendingPastesAsync()){Console.WriteLine("{0} - {1}",paste.Title,paste.Url);}//you can create pastes directly from Pastebin static class but they are created as guests and you have a limited number of guest uploadsPasteanotherPaste=awaitPaste.CreateAsync("another paste","MyPasteTitle2",Language.CSharp,Visibility.Unlisted,Expiration.OneHour);Console.WriteLine(anotherPaste.Title);}catch(PastebinExceptionex)//api throws PastebinException{//in the Parameter property you can see what invalid parameter was sent//here we check if the exeption is thrown because of invalid login detailsif(ex.Parameter==PastebinException.ParameterType.Login){Console.Error.WriteLine("Invalid username/password");}else{throw;//all other types are rethrown and not swalowed!}}Console.ReadKey();}}}

About

API client for Pastebin in C#

Topics

Resources

Stars

28 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages