Public Class Form1
Dim load, login, logout, tweet, cektweet As Boolean
Dim iP As Integer = 0
Private WithEvents TmrCek As New Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
load = True
Btnlogin.Enabled = False
BtnLogout.Enabled = False
WB.Navigate("https://mobile.twitter.com/session/new")
With TmrCek
.Interval = 1000
.Start()
End With
End Sub
Private Sub TxtPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtPass.KeyDown
If e.KeyCode = Keys.Enter Then Btnlogin_Click(sender, e)
End Sub
Private Sub Btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnlogin.Click
If TxtEmail.Text = Nothing Then
TxtEmail.Focus()
Return
End If
If TxtPass.Text = Nothing Then
TxtPass.Focus()
Return
End If
Btnlogin.Enabled = False
Application.DoEvents()
With WB
.Document.GetElementById("session[username_or_email]").SetAttribute("value", TxtEmail.Text)
.Document.GetElementById("session[password]").SetAttribute("value", TxtPass.Text)
If .Document.Body.InnerHtml.Contains("signupbutton") Then
.Document.GetElementById("signupbutton").InvokeMember("click")
ElseIf .Document.Body.InnerHtml.Contains("commit") Then
For Each input As HtmlElement In .Document.GetElementsByTagName("input")
If input.OuterHtml.Contains("commit") Then
input.InvokeMember("click")
End If
Application.DoEvents()
Next
End If
End With
login = True
With TmrCek
.Interval = 1000
.Start()
End With
End Sub
Private Sub BtnLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogout.Click
BtnLogout.Enabled = False
Application.DoEvents()
For Each inputTag As HtmlElement In WB.Document.GetElementsByTagName("a")
If inputTag.OuterHtml.Contains("/account") Then
inputTag.InvokeMember("click")
logout = True
End If
Application.DoEvents()
Next
With TmrCek
.Interval = 1000
.Start()
End With
End Sub
Private Sub BtnTweet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTweet.Click
If Btnlogin.Enabled = True Then
TxtEmail.Focus()
Return
End If
If TxtTweet.Text = Nothing Then
TxtTweet.Focus()
Return
End If
If WB.DocumentText.Contains("/compose/tweet") = False Then Return
BtnTweet.Enabled = False
Application.DoEvents()
For Each input As HtmlElement In WB.Document.GetElementsByTagName("a")
If input.OuterHtml.Contains("/compose/tweet") Then
input.InvokeMember("click")
End If
Application.DoEvents()
Next
tweet = True
With TmrCek
.Interval = 1000
.Start()
End With
End Sub
Private Sub TmrCek_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrCek.Tick
TmrCek.Stop()
If load Then
iP += 1
If iP = 5 Then
iP = 0
load = False
Try
If WB.Document.Body.InnerHtml.Contains("session[username_or_email]") Then
Btnlogin.Enabled = True
BtnLogout.Enabled = False
Return
Else
Err:
MsgBox("Error loading webpage", MsgBoxStyle.Critical, Text)
Return
End If
Catch ex As Exception
GoTo Err
End Try
End If
End If
If login Then
iP += 1
If iP = 3 Then
iP = 0
login = False
If WB.Document.Body.InnerHtml.Contains("session[username_or_email]") Then
Btnlogin.Enabled = True
BtnLogout.Enabled = False
MsgBox("The email and password you entered did not match our records." _
& vbCrLf & "Please double-check and try again. ", MsgBoxStyle.Critical, Text)
Return
Else
For Each inputTag As HtmlElement In WB.Document.GetElementsByTagName("a")
If inputTag.OuterHtml.Contains("/account") Then
BtnLogout.Enabled = True
Return
End If
Application.DoEvents()
Next
End If
End If
End If
If logout Then
iP += 1
If iP = 3 Then
iP = 0
logout = False
For Each input As HtmlElement In WB.Document.GetElementsByTagName("input")
If input.OuterHtml.Contains("Log out") Then
input.InvokeMember("click")
End If
Application.DoEvents()
Next
Btnlogin.Enabled = True
Return
End If
End If
If tweet Then
iP += 1
If iP = 2 Then
iP = 0
tweet = False
WB.Document.GetElementById("tweet[text]").SetAttribute("value", TxtTweet.Text)
WB.Document.GetElementById("commit").InvokeMember("click")
cektweet = True
With TmrCek
.Interval = 1000
.Start()
End With
Return
End If
End If
If cektweet Then
iP += 1
If iP = 3 Then
iP = 0
If WB.Document.Body.InnerHtml.Contains(TxtTweet.Text) Then
cektweet = False
BtnTweet.Enabled = True
Return
End If
End If
End If
TmrCek.Start()
End Sub
Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
BtnTweet.Enabled = True
With TxtTweet
.Clear()
.Focus()
End With
End Sub
End Class
Anda baru saja membaca artikel yang berkategori Social Media /
Twitter /
VB.Net
dengan judul FASTEST VB.Net Twitter Login and Post Tweet. Anda bisa bookmark halaman ini dengan URL http://vbcodesblog.blogspot.com/2016/04/fastest-vbnet-twitter-login-and-post.html. Terima kasih!
Ditulis oleh:
Farray Cool - Monday, April 11, 2016
Belum ada komentar untuk "FASTEST VB.Net Twitter Login and Post Tweet"
Post a Comment