Pastebin.com API Wrapper for .NET
Download link: PasteBinAPI.rar
1 - Reference the DLL in your project and add the following directive:
using MadScripterWrappers;2 - Create an instance of the PBApi class with your developer key (You will find your developer key here: pastebin.com/api):
PBApi api = new PBApi("YOUR DEV KEY");3 - Creating a new paste:
api.CreatePaste("The code", "The title", "The user key", PBApi.PasteType.Private, PBApi.ExpireDate._10M, PBApi.PasteFormat.text);
Note: if the user key is empty or invalid, the paste will be posted as “a guest”.
3.a - The type of the paste:
“PBApi.PasteType” is an enumeration that contains the 3 types that you can use to set the visibility of your paste:
- PBApi.PasteType.Public = The paste will be public.
- PBApi.PasteType.Unlisted = The paste will be unlisted.
- PBApi.PasteType.Private = The paste will be private (only allowed in combination with the “user key” as you have to be logged into your account to access the paste).
3.b - The expiration date:
“PBApi.ExpireDate” is an enumeration that contains the 7 valid values for setting the expiration date of a paste:
- PBApi.ExpireDate.N = Never
- PBApi.ExpireDate._10M = 10 Minutes
- PBApi.ExpireDate._1H = 1 Hour
- PBApi.ExpireDate._1D = 1 Day
- PBApi.ExpireDate._1W = 1 Week
- PBApi.ExpireDate._2W = 2 Weeks
- PBApi.ExpireDate._1M = 1 Month
3.c - The highlighting syntax:
“PBApi.PasteFormat” is an enumeration that contains over 200 syntax highlighting options. More info here: pastebin.com/api#5
4 - Creating a user key:
api.CreateAPIUserKey("username", "password");
5 - Listing a user’s pastes:
api.ListUserPastes("The user key", *results limit);
* optional parameter. By default it is set to 50, minimum value is 1, maximum value is 1000.
5.a - Deserializing the output of a user’s paste listing:
- 1 - Add the following directives:
using System.Xml.Serialization;
using System.IO;
- 2 - The code:
XmlSerializer deserializePastesOutput = new XmlSerializer(typeof(PBPaste));
string pastesOutput = api.ListUserPastes("The user key");
using(TextReader reader = new StreamReader(pastesOutput.ToStream())
{
object obj = deserializePastesOutput.Deserialize(reader);
PBPaste data = (PBPaste)obj;
}
* PBPaste is the class for deserializing the pastes.
* .ToStream() is an extension method to convert a string to a stream.
- 3 - PBPaste properties:
- paste_key - paste_date - paste_title -paste_size - paste_expire_date - paste_private - paste_format_long - paste_format_short - paste_url - paste_hits.
6 - Listing trending pastes:
api.ListTrendingPastes();Note: for deserializing the trending pastes, use the same process as before, the class is always “PBPaste”.
7 - Deleting a user’s paste:
api.DeletePaste("The user key", "The paste key");
Note: to get a paste key, take a paste link, example: “http://pastebin.com/gNe3hJAH”, and remove “http://pastebin.com/”.
Here’s a simple method that does that:
private string GetPasteKey(string url)
{
return url.Replace("http://pastebin.com/", "");
}
8 - Getting the information and settings of a user:
api.GetUserDetails("The user key");
8.a - Deserializing the output of a user information listing:
Use the same process as for the pastes but instead of using the “PBPaste” class, use the “PBUser” class.
- PBUser properties:
- user_name - user_format_short - user_expiration - user_avatar_url - user_private - user_website - user_email - user_location - user_account_type.
9 - Getting the raw output of a paste:
api.GetRawOutput("The paste key");
10 - Creating a paste from a file:This method has 2 overloads.
- 1 - First overload:
api.CreatePasteFromFile("The path to the file", "The user key", PBApi.PasteType.Private,
PBApi.ExpireDate._10M,
PBApi.PasteFormat.text);
This one uses the file name as a title.
- 2 - Second overload:
api.CreatePasteFromFile("The path to the file", "The title", "The user key", PBApi.PasteType.Private,
PBApi.ExpireDate._10M,
PBApi.PasteFormat.text);
This one allows you to choose the title of the paste.
