[WM][VB][Twitter]

  • 3073
  • 0
  • 2009-07-28

[WM][VB][Twitter]

twitter

twitter可以說是種微型blog?可登錄140個英文字(70個中文字),在訊息裡面你可以任意輸入所想要表達的文字或是想法也可來個火星文 orz,在國外的特定電信業者可以即時簡訊通知喔。首先你必需要到 http://twitter.com/ 申請一個帳號。

 

Step1:在 VS2008 新增一個智慧型裝置專案,在表單上面提供三個輸入文字方塊分別為帳號、密碼、訊息以及一個功能表傳送按鍵如下圖所示

image

 

Step2:在 Form1 下功能表 [Send] 撰寫下列程式碼:

       Dim uri As String = "http://twitter.com/statuses/update.xml?status=" & txtUpdate.Text & "&source=Twitterizer"
       Dim Request As HttpWebRequest = CType(WebRequest.Create(uri), HttpWebRequest)
       Request.Method = "POST"
       Dim readStream As StreamReader
       Request.Credentials = New NetworkCredential(txtUser.Text, txtPassword.Text)
       Dim Response As HttpWebResponse
       Try
           Response = CType(Request.GetResponse(), HttpWebResponse)
           Dim receiveStream As Stream = Response.GetResponseStream()
           readStream = New StreamReader(receiveStream, Encoding.UTF8)
           Response.Close()
           readStream.Close()
           MsgBox("OK")
       Catch ex As Exception
           MsgBox(ex.ToString)
       End Try

       ps: txtUser 是登入twitter帳號, txtPassword為密碼,txtUpdate則是發送的訊息

 

Step3:寫好程式碼就開始在 VS2008功能表上執行部署[偵錯]\[開始偵錯],把程式送到手機上。接著把帳號、密碼、訊息輸入一下,在按下[Send] 傳送訊息如果沒問題就會顯示 ok 有問題就有 Exception

image

 

Step4:接下來連回到自已的 twitter web site 去看一下,訊息是否有更新這樣就大功告成啦

image

 

未完待續