Membuat Login Twitter dari VB.NET

Kali ini saya akan posting bagaimana cara membuat login dari program aplikasi vb.net ke twitter
langsung saja
Buat TextBox 2
dan 1 button





    Imports System.IO
    Imports System.Text
    Imports System.Net
    Imports System.Text.RegularExpressions
    Public Class Form1
    Private Function GetBetween(ByVal Source As String, ByVal Str1 As String, ByVal Str2 As String, Optional ByVal Index As Integer = 0) As String
    Return Regex.Split(Regex.Split(Source, Str1)(Index + 1), Str2)(0)
    End Function
    Dim loginCookies As CookieContainer
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim token As String = getToken()
    Dim postData As String = "session%5Busername_or_email%5D=" & TextBox1.Text & "&session%5Bpassword%5D=" & TextBox2.Text & "&remember_me=1&return_to_ssl=false&scribe_log=&redirect_after_login=%2F&authenticity_token=" & token
    Dim tempCookies As New CookieContainer
    Dim encoding As New UTF8Encoding
    Dim byteData As Byte() = encoding.GetBytes(postData)
    
    Dim r As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://twitter.com/sessions"), HttpWebRequest)
    r.KeepAlive = True
    r.Method = "POST"
    r.CookieContainer = tempCookies
    r.ContentType = "application/x-www-form-urlencoded"
    r.Referer = "https://twitter.com/sessions"
    r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36"
    r.ContentLength = byteData.Length
    Dim re As Stream = r.GetRequestStream()
    re.Write(byteData, 0, byteData.Length)
    re.Close()
    Dim res As HttpWebResponse = DirectCast(r.GetResponse(), HttpWebResponse)
    tempCookies.Add(res.Cookies)
    loginCookies = tempCookies
    Dim src As String = New StreamReader(res.GetResponseStream()).ReadToEnd()
    If (src.Contains("View my profile page")) Then
    loginCookies = tempCookies
    MsgBox("Success!")
    Else
    tempCookies = Nothing
    MsgBox("Failed.")
    End If
    End Sub
    
    Private Function getToken()
    Dim r As HttpWebRequest = HttpWebRequest.Create("http://www.twitter.co.uk")
    Dim re As HttpWebResponse = r.GetResponse()
    Dim src As String = New StreamReader(re.GetResponseStream()).ReadToEnd()
    Return GetBetween(src, "<input type=""hidden"" name=""authenticity_token"" value=""", """")
    End Function
    End Class

Tulisan Terkait

Membuat Login Twitter dari VB.NET
4/ 5
Oleh

Berlangganan via email

Senang dengan tulisan di atas? Silahkan berlangganan posting terbaru langsung melalui email.