Hi guys, today I finished to code some classes to make a Paste on Pastebin. I used the API to simplify my job.
Today I released the class to an italian forum, now let's post here
VB.NET Version
Code:
Imports System.Collections.Specialized
Imports System.Net
Imports System.Text
Public Class Paste
Dim _devkey As String
Dim _username As String
Dim _userpassword As String
Dim _PasteCode As String
Dim _PasteName As String
Dim _Syntax As String
Dim _ExpireDate As String
Dim _PasteExposure As Integer
Dim ukey As String
Sub New(ByVal Key As String, ByVal username As String, ByVal password As String, ByVal PasteCode As String, _
ByVal PasteName As String, ByVal PasteExposure As Integer, ByVal SyntaxHighlighting As String, _
ByVal ExpireDate As String)
_devkey = Key
_username = username
_userpassword = password
_PasteCode = PasteCode
_PasteName = PasteName
_PasteExposure = PasteExposure
_Syntax = SyntaxHighlighting
_ExpireDate = ExpireDate
End Sub
Public Function Start() As String
Dim chiavi As New NameValueCollection()
chiavi.Add("api_dev_key", _devkey)
chiavi.Add("api_user_name", _username)
chiavi.Add("api_user_password", _userpassword)
Dim wClient As New WebClient()
Dim risposta As String = Encoding.UTF8.GetString(wClient.UploadValues("https://pastebin.com/api/api_login.php", chiavi))
If risposta.ToLower.Contains("bad api request") Then
MessageBox.Show("Login failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return "ERROR"
Else
ukey = risposta
Try
Dim output As String = MakePaste() 'Restituisce una stringa
Process.Start(output)
Return "SUCCESS"
Catch Ex As Exception
MessageBox.Show("Exception: " & Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return "ERROR"
End Try
End If
End Function
Public Function MakePaste() As String
If ukey = "" Then Return "ERROR"
Dim chiavi As New NameValueCollection()
chiavi.Add("api_dev_key", _devkey)
chiavi.Add("api_user_key", ukey)
chiavi.Add("api_option", "paste")
chiavi.Add("api_paste_code", _PasteCode)
chiavi.Add("api_paste_name", _PasteName)
chiavi.Add("api_paste_format", _Syntax)
chiavi.Add("api_paste_private", _PasteExposure)
chiavi.Add("api_paste_expire_date", "N")
Dim wc As New WebClient()
Dim Risultato As String = ""
Dim Risposta As String = Encoding.UTF8.GetString(wc.UploadValues( _
"https://pastebin.com/api/api_post.php", chiavi))
If Risposta.ToLower.Contains("bad api request") Then
' Key non valida
Else
Risultato = Risposta
End If
Return Risultato
End Function
End Class
C# Version
Code:
using System.Collections.Specialized;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System;
public class Paste
{
private string _devkey;
private string _username;
private string _userpassword;
private string _PasteCode;
private string _PasteName;
private string _Syntax;
private string _ExpireDate;
private int _PasteExposure;
private string ukey;
public Paste(string Key, string username, string password, string PasteCode, string PasteName, int PasteExposure, string SyntaxHighlighting, string ExpireDate)
{
_devkey = Key;
_username = username;
_userpassword = password;
_PasteCode = PasteCode;
_PasteName = PasteName;
_PasteExposure = PasteExposure;
_Syntax = SyntaxHighlighting;
_ExpireDate = ExpireDate;
}
public string Start()
{
NameValueCollection chiavi = new NameValueCollection();
chiavi.Add("api_dev_key", _devkey);
chiavi.Add("api_user_name", _username);
chiavi.Add("api_user_password", _userpassword);
WebClient wClient = new WebClient();
string risposta = Encoding.UTF8.GetString(wClient.UploadValues("https://pastebin.com/api/api_login.php", chiavi));
if (risposta.ToLower().Contains("bad api request"))
{
MessageBox.Show("Login failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return "ERROR";
}
else
{
ukey = risposta;
try
{
string output = MakePaste();
Process.Start(output);
return "SUCCESS";
}
catch (Exception Ex)
{
MessageBox.Show("Exception: " + Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return "ERROR";
}
}
}
public string MakePaste()
{
if (ukey == "")
{
return "ERROR";
}
NameValueCollection chiavi = new NameValueCollection();
chiavi.Add("api_dev_key", _devkey);
chiavi.Add("api_user_key", ukey);
chiavi.Add("api_option", "paste");
chiavi.Add("api_paste_code", _PasteCode);
chiavi.Add("api_paste_name", _PasteName);
chiavi.Add("api_paste_format", _Syntax);
chiavi.Add("api_paste_private", _PasteExposure.ToString());
chiavi.Add("api_paste_expire_date", "N");
WebClient wc = new WebClient();
string Risultato = "";
string Risposta = Encoding.UTF8.GetString(wc.UploadValues("https://pastebin.com/api/api_post.php", chiavi));
if (Risposta.ToLower().Contains("bad api request"))
{
}
else
{
Risultato = Risposta;
}
return Risultato;
}
}
Now let's create an instance of the class. On the button "Create paste" put:
VB.NET
Code:
Dim Maker As New Paste("your pastebin API", "your pastebin username", "your pastebin password", txtCode.Text, _
"paste name", 1, "php", "N")
' Parameter ExpireDate> N= Never // 1M= 1 Month // 10M= 10 Minutes e così via, etc...
' Parameter PasteExposure> 0= Public // 1= Unlisted // 2= Private
Maker.Start()
C#
Code:
Paste np = new Paste("your pastebin API key", "your pastebin username", "your pastebin password", txtCode.Text, "paste name", 2, "php", "N");
np.Start();
Thanks for watching this post!
See you
- - - Updated - - -
Edit // Proof: https://gyazo.com/4ead8bbd0375dbd8740a36f7240b468d