Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Pastebin API Library

In my spare time I made an easy way to use the Pastebin API. I'm relatively new to coding DLL's so feedback would be appreciated.

Code
APIKey = Your API Key
Paste(Paste's Text, Public, Text Style, Expire Time, Paste's Title)

Text Style Code List, Get your API Key at http://pastebin.com/api .

Example Usage

[Image: FOOwE95.png]


Here's the source, have fun.
Code
Public Class Paster

    Public APIKey As String = "Undefined"

    Public Function Paste(ByVal Text As String, ByVal Listed As Boolean, ByVal Format As String, ByVal ExpireTime As String, ByVal Name As String)
  Try

    ' --Set Variables
    Dim var1 As String
    Dim var2 As String = Format
    Dim var3 As String = ExpireTime
    Dim var4 As String = Name
    If Listed = True Then
    var1 = "0"
    Else
    var1 = "1"
    End If

    ' --POST Req
    Dim b As New System.Net.WebClient()
    Dim g As String = "?api_paste_private=" & var1 & "&api_option=paste" & "&api_paste_format=" & var2 & "&api_paste_expire_date=" & var3 & "&api_dev_key=" & APIKey & "&api_paste_name=" & var4 & "&api_paste_code=" & Text
    b.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
    Dim c As Byte() = System.Text.Encoding.ASCII.GetBytes(g)
    Dim d As Byte() = b.UploadData("http://pastebin.com/api/api_post.php", "POST", c)

    ' --Return Value
    Return System.Text.Encoding.ASCII.GetString(d)

    ' --Error Handling
  Catch x As Exception
    Return "Error"
  End Try

    End Function

End Class
why dll and not the class its very simple with key as here http://pastebin.com/api
(Jan 24, 2013 09:04 AM)Only3 Wrote:  why dll and not the class its very simple with key as here http://pastebin.com/api

For ease of use. Also, just practicing making Libraries.
You can still post the class'es code.
Due to popular request, PM me if you want the source.
(Jan 24, 2013 10:06 AM)antiven0m Wrote:  Due to popular request, PM me if you want the Class.
Are you retarded or something? haha...
(Jan 24, 2013 10:11 AM)Superuser Wrote:  Are you retarded or something? haha...
I don't see any reason for you to ask?
The point is why would people post pm for a source code to an api thats very simple to understand and is well documented online.
(Jan 24, 2013 10:22 AM)Not2EXceL Wrote:  The point is why would people post pm for a source code to an api thats very simple to understand and is well documented online.

I do the PM thing so I can actually see if there is interest in what I spent time coding. I want to feel like I've accomplished something by making all this.. And if it's easy, then people can code it for themselves. I'm not saying it hard to code, and i'm not asking a lot to get it. Is it impossible to release something in this section?

EDIT: Released it anyways... oh well.
Below is a PHP example using cURL how to create a new paste:
PHP Code

<?php 
$api_dev_key 
= ' key '; // your api_developer_key
$api_paste_code = 'just some random text you :)'; // your paste text
$api_paste_private = '1'; // 0=public 1=unlisted 2=private
$api_paste_name = 'justmyfilename.php'; // name or title of your paste
$api_paste_expire_date = '10M';
$api_paste_format     = 'php';
$api_user_key = ''; // if an invalid api_user_key or no key is used, the paste will be create as a guest
$api_paste_name = urlencode($api_paste_name);
$api_paste_code = urlencode($api_paste_code);

$url = 'http://pastebin.com/api/api_post.php';
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_user_key='.$api_user_key.'&api_paste_private='.$api_paste_private.'&api_paste_name='.$api_paste_name.'&api_paste_expire_date='.$api_paste_expire_date.'&api_paste_format='.$api_paste_format.'&api_dev_key='.$api_dev_key.'&api_paste_code='.$api_paste_code.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);

$response  = curl_exec($ch);
echo 
$response; 

Possible Good API Responses: (example) http://pastebin.com/UIFdu235s

Use -
MsgBox(New System.IO.StreamReader(Net.HttpWebRequest.Create("http://ursite.com/api.php").GetResponse.GetResponseStream()).ReadToEnd)
(Jan 24, 2013 10:38 AM)Only3 Wrote:  Below is a PHP example using cURL how to create a new paste:
PHP Code

<?php 
$api_dev_key 
= ' key '; // your api_developer_key
$api_paste_code = 'just some random text you :)'; // your paste text
$api_paste_private = '1'; // 0=public 1=unlisted 2=private
$api_paste_name = 'justmyfilename.php'; // name or title of your paste
$api_paste_expire_date = '10M';
$api_paste_format     = 'php';
$api_user_key = ''; // if an invalid api_user_key or no key is used, the paste will be create as a guest
$api_paste_name = urlencode($api_paste_name);
$api_paste_code = urlencode($api_paste_code);

$url = 'http://pastebin.com/api/api_post.php';
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_user_key='.$api_user_key.'&api_paste_private='.$api_paste_private.'&api_paste_name='.$api_paste_name.'&api_paste_expire_date='.$api_paste_expire_date.'&api_paste_format='.$api_paste_format.'&api_dev_key='.$api_dev_key.'&api_paste_code='.$api_paste_code.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);

$response  = curl_exec($ch);
echo 
$response; 

Possible Good API Responses: (example) http://pastebin.com/UIFdu235s

Use -
MsgBox(New System.IO.StreamReader(Net.HttpWebRequest.Create("http://ursite.com/api.php").GetResponse.GetResponseStream()).ReadToEnd)

Mine doesn't reference to an online API. It sends a POST Request.
Public Function PasteBinUpload(ByVal code As String) As String
System.Net.ServicePointManager.Expect100Continue = False
Dim pr As Integer = 0
Dim fi As String = "?paste_private=" & pr & "&paste_format=text" & "&paste_code=" & code
Dim w As New System.Net.WebClient()
w.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim pd As Byte() = System.Text.Encoding.ASCII.GetBytes(fi)
Dim rd As Byte() = w.UploadData("http://pastebin.com/api_public.php", "POST", pd)
Dim r As String = System.Text.Encoding.ASCII.GetString(rd)
Return r
End Function

theres many examples on web this one quick search of the section
(Jan 24, 2013 10:47 AM)Only3 Wrote:  Public Function PasteBinUpload(ByVal code As String) As String
System.Net.ServicePointManager.Expect100Continue = False
Dim pr As Integer = 0
Dim fi As String = "?paste_private=" & pr & "&paste_format=text" & "&paste_code=" & code
Dim w As New System.Net.WebClient()
w.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim pd As Byte() = System.Text.Encoding.ASCII.GetBytes(fi)
Dim rd As Byte() = w.UploadData("http://pastebin.com/api_public.php", "POST", pd)
Dim r As String = System.Text.Encoding.ASCII.GetString(rd)
Return r
End Function

theres many examples on web this one quick search of the section

I'm sure there are, I didn't invent POST Requests.
(Jan 24, 2013 10:41 AM)antiven0m Wrote:  Mine doesn't reference to an online API. It sends a POST Request.

I just looked at your source you posted, and it does reference to the pastebin api -_-

The example they give is post as well.

[img]http://img843.imageshack.us/img843/7695/4f96924d18c141339368892.png[/img]

just please don't make yourself look anymore stupid
(Jan 24, 2013 10:52 AM)Not2EXceL Wrote:  I just looked at your source you posted, and it does reference to the pastebin api -_-

The example they give is post as well.

[img]http://img843.imageshack.us/img843/7695/4f96924d18c141339368892.png[/img]

just please don't make yourself look anymore stupid

You misunderstood my words. Not referencing to an API other than the Pastebin API. He was stating that it could reference another API with the code in the above picture you posted.

EDIT: This section may be the biggest group of bigots I've seen.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by SIM-3437924Jul 2, 2021 12:02 PM 6 362 Jul 2, 2021 12:02 PM
Last Post: sigmasmom
[C] by phisnNov 11, 2020 08:44 AM 1 165 Nov 11, 2020 08:44 AM
Last Post: HFDone
[Java] by GlushkoJun 13, 2018 11:13 PM 3 640 Jun 13, 2018 11:13 PM
Last Post: hostov