Sarah ([info]sarahs_muse) wrote,

Twittering from VBScript



Yeah, I know it's pointless and simple - but here's a quick and simple Twitter update program in VBScript. I originally started work on this program to do some cookie manipulations - but the Twitter API uses simple authentication, and the alternative was oAuth - which uses "by application" authentication that I wasn't interested in programming for.

I guess you could change it so when you go over 160 characters, your post is split into two or more posts - like text messages do. =D


It gives you access to "The Official Twitter Text Commands" too!
http://help.twitter.com/portal

Anyway, here it is:

Twitter.vbs



user="USERNAME GOES HERE"

password="PASSWORD GOES HERE"

postData="TWITTER UPDATE HERE!"

'''''''''''''''

url = "http://twitter.com/statuses/update.xml"

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", url, false

'we need to setrequestheaders twice due to KB article Q234486.
xmlhttp.setRequestHeader "cookie", "x=y"
xmlhttp.setRequestHeader "User-Agent","User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)"
xmlhttp.setRequestHeader "Referer","http://twitter.com/"
xmlhttp.setRequestHeader "ACCEPT-LANGUAGE", "en-us"
xmlhttp.setRequestHeader "Accept", "*/*"
xmlhttp.setRequestHeader "Pragma","no-cache"
xmlhttp.setRequestHeader "Authorization","Basic " & encodeBase64(user & ":" & password)

encodedPost="status=" & URLEncode(postData)
wscript.echo encodedPost
xmlhttp.send encodedPost

wscript.echo xmlhttp.getAllResponseHeaders
wscript.echo xmlhttp.responseText

function encodeBase64(textData)
   set XMLDOM = CreateObject("Microsoft.XMLDOM")
   set tempElement = XMLDOM.createElement("temp")
   set stream = CreateObject("ADODB.Stream")
   stream.type = 2' adTypeText
   stream.charSet = "us-ascii"
   stream.open
   stream.writeText textData
   stream.position = 0
   stream.type = 1 ' adTypeBinary
   stream.position = 0
   tempElement.dataType = "bin.base64"
   tempElement.nodeTypedValue = stream.Read
   encodeBase64 = tempElement.text
end function

function URLEncode(data)
   for i = 1 to len(data)
      c = asc(mid(data,i,1))
      if c = 32 then
         out = out + "+"
      elseif (c < 48 or c>126) or (c>56 and c<=64) then
         out = out + "%" + hex(c)
      else
         out = out + chr(c)
      end if
   next
   URLEncode = out
end function

  • Post a new comment

    Error

  • 3 comments

Anonymous

July 24 2009, 18:52:20 UTC 2 years ago

Made an similar script

I have made a similar script, it can be found here: http://sitejunction.awardspace.com/vbscript_tweets/

[info]sarahs_muse

July 24 2009, 18:58:21 UTC 2 years ago

Re: Made an similar script

That's excellent!

I noticed a little bug:
http://sitejunction.awardspace.com/vbscript_tweets/desktop_script/

The HTA link at the bottom links back to "basic_script"!

Anonymous

August 6 2009, 18:51:38 UTC 2 years ago

Re: Made an similar script

Thanks, I have corrected it!

Regards,
Erick
http://sitejunction.awardspace.com/vbscript_tweets/ (http://sitejunction.awardspace.com/vbscript_tweets/)

Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…