1

我正在寻找如何使用 pastebin 的 api 来发帖。我想要它做的是让它登录到一个 pastebin 帐户并发布一个字符串。我真的不知道如何做到这一点,任何帮助表示赞赏。谢谢!

他们的 API 可以在这里找到:http: //pastebin.com/api

4

1 回答 1

0

试试这个,先登录生成user_key 把帖子贴上新

 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
于 2013-08-17T11:48:40.417 回答