我正在寻找如何使用pastebin的api发帖子。我想要它做的是让它登录到一个pastebin帐户并发布一个字符串。我根本不知道如何做到这一点,任何帮助表示赞赏。谢谢!
可以在此处找到他们的API:http://pastebin.com/api
答案 0 :(得分: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