Twitter with VB follow up
The video for this is a bit choppy. The fundamental process is:
- get the twitter.vb in place.
- update the Username,Password lines.
- A textbox for status (statusText) updates and a textbox for results (results).
- A button for posting and a button for friend timeline
- Onclick of post button calls results.text=PostStatus(status.text)
- Onclick of FriendTimeline button calls
results.text=push(username,password,FriendTimeline)
Download Project
Twitter simple with VB.NET
Thought I would share my homebrew Twitter framework. I'll post a sample app using it in a bit.
Imports System
Imports System.IO
Imports System.Net
Imports System.Web
Public Module twitter
'hard coded for testing
Public username As String = "YOUR USER NAME"
Public password As String = "YOUR PASSWORD"
Public FriendTimeline As String = "http://twitter.com/statuses/friends_timeline/{0}.xml"
Public Publictimeline As String = "http://twitter.com/statuses/public_timeline.xml"
Public Archive As String = "http://twitter.com/statuses/user_timeline/{0}.xml"
Public Replies As String = "http://twitter.com/statuses/replies.xml"
Public Direct As String = "http://twitter.com/direct_messages.xml"
Public AuthUser As String = "http://twitter.com/account/verify_credentials.xml"
Public Update As String = "http://@twitter.com/statuses/update.xml"
Public Followers As String = "http://twitter.com/statuses/followers.xml"
Public Function Push(ByVal username As String, _
ByVal password As String, _
ByVal action As String, _
Optional ByVal mode As Integer = 0) As String
Dim req As WebRequest
If mode = 0 Then
req = HttpWebRequest.Create(String.Format(action, username))
Else
req = HttpWebRequest.Create(String.Format(action))
End If
req.Credentials = New NetworkCredential(username, password)
Try
'returns raw xml
Dim res As WebResponse = req.GetResponse()
Dim ret As StreamReader = New StreamReader(res.GetResponseStream())
Dim retData As String = ret.ReadToEnd()
ret.Close()
Return retData.ToString
Catch ex As Exception
Return "There was an error please try again..."
End Try
End Function
Public Function PostStatus(ByVal status As String) As String
Dim ret As String
Dim req As WebRequest = HttpWebRequest.Create(Update)
System.Net.ServicePointManager.Expect100Continue = False
req.Credentials = New NetworkCredential(username, password)
req.ContentType = "application/x-www-form-urlencoded"
req.Method = "POST"
Dim encoding As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
Dim bt() As Byte = encoding.GetBytes(String.Format("status={0}", status))
Dim s As Stream
Try
req.ContentLength = bt.Length
s = req.GetRequestStream()
s.Write(bt, 0, bt.Length)
Catch ex As Exception
Throw ex
End Try
Try
'returns raw xml
Dim res As WebResponse = req.GetResponse()
If res Is Nothing Then
Return Nothing
End If
Dim sr As StreamReader = New StreamReader(res.GetResponseStream())
ret = sr.ReadToEnd().Trim()
sr.Close()
Catch ex As Exception
Throw ex
End Try
Return ret
End Function
End Module
Google Charts Abuse
I know almost nothing about Google Charts, but playing around with it seemed like a fun idea. So here goes
The Code
< img src="http://chart.apis.google.com/chart?
cht=lc&chs=500x400
&chd=t:0,100|1,99|2,98|3,97|4,96|5,95|6,94|
7,93|8,92|9,91|10,90|11,89|12,88|13,87|14,86|
15,85|16,84|17,83|18,82|19,81|20,80|21,79|22,78|
23,77|24,76|25,75|26,74|27,73|28,72|29,71|30,70|
31,79|32,78|33,77|34,76|35,75|36,74|37,73|38,72|
39,71|40,70|41,69|42,68|43,67|44,66|45,65|46,64|
47,63|49,62|50,61">
Seems there are lots of possiblities here for some creative abuse