?

Log in

No account? Create an account
Twittering from VBScript - Sarah's Blog [entries|archive|friends|userinfo]
Sarah

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Twittering from VBScript [May. 2nd, 2009|08:22 am]
Sarah


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
linkReply

Comments:
From: (Anonymous)
2009-07-24 06:52 pm (UTC)

Made an similar script

I have made a similar script, it can be found here: http://sitejunction.awardspace.com/vbscript_tweets/
(Reply) (Thread)
[User Picture]From: sarahs_muse
2009-07-24 06:58 pm (UTC)

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"!
(Reply) (Parent) (Thread)
From: (Anonymous)
2009-08-06 06:51 pm (UTC)

Re: Made an similar script

Thanks, I have corrected it!

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

(Reply) (Parent) (Thread)