Make a post to pastebin using their API in VB..net

1.5k Views Asked by At

I am looking to find out how to make a post using pastebin's api. What I want it to do is have it so it logs into a pastebin account and posts a string. I don't really know how to do this at all, any help is appreciated. Thanks!

Their API can be found here: http://pastebin.com/api

1

There are 1 best solutions below

0
On

Try this, first login to generate user_key the post a new paste

 Private Const login_url As String = "http://pastebin.com/api/api_login.php"
    Private Const post_url As String = "http://pastebin.com/api/api_post.php"
    Private Const dev_key As String = "32e06c2da46f91db964deb1a33db8ab0"
    Private Const user_name As String = "??????"
    Private Const user_password As String = "???????"
    Private user_key As String = ""

    Public Sub CallIt()
        'Login to generate the user_key
        If Login() Then
            ' Then post a new paste
            Dim PasteURL As String = Post("Code", "Name", "vb")

        End If
    End Sub

    Public Function Login() As Boolean

        Dim Data As New NameValueCollection()
        Data.Add("api_dev_key", dev_key)
        Data.Add("api_user_name", user_name)
        Data.Add("api_user_password", user_password)

        Dim Status As Boolean = True
        Using Client As New WebClient()
            Dim Response As String = Encoding.UTF8.GetString(Client.UploadValues(login_url, Data))

            If Response.Contains("Bad API request") Then
                Status = False
            Else
                user_key = Response
            End If

        End Using

        Return Status
    End Function

    Public Function Post(ByVal paste_code As String, _
                         ByVal paste_name As String, _
                         ByVal paste_format As String) As String
        If user_key = "" Then Return False

        Dim Data As New NameValueCollection()
        Data.Add("api_dev_key", dev_key)
        Data.Add("api_user_key", user_key)
        Data.Add("api_option", "paste")
        Data.Add("api_paste_code", paste_code)
        Data.Add("api_paste_name", paste_name)
        Data.Add("api_paste_format", paste_format)
        Data.Add("api_paste_private", "2")  '0=public 1=unlisted 2=private
        Data.Add("api_paste_expire_date", "N")

        Dim PasteURL As String = ""
        Using Client As New WebClient()
            Dim Response As String = Encoding.UTF8.GetString(Client.UploadValues(post_url, Data))

            If Not Response.Contains("Bad API request") Then
                PasteURL = Response
            End If
        End Using

        Return PasteURL
    End Function