Tweet your ideas through JavaScript

Do you have a website and would like to post your tweets from it ? Or maybe you want to create a widget that posts weather on your twitter account?

I encountered this situation and overcome it with the following script. It is pretty simple, but beware that JavaScript is run on CLIENT side, thus any code must be sent in clear.Since it is needed that you provide a password for your account, would not be so wise to put it in clear.

NOTE: I use it for a Vista sidebar gadget, so only IE code is below. For FireFox or Opera the modifications are trivial.

So let’s code speak for itself:

function TweetIt(textToTweet ){
  // first some configurations
  var username = "twitter_user";
  var password = "twitter_pass";  
  //create the request
  var request = new ActiveXObject("Msxml2.XMLHTTP.3.0");
  // post the tweet
    "POST", //we want to post the update
    "" + textToTweet, 
   //document.write("" + txt);
  // receive the response asyncroniously
  request.onreadystatechange = function()
      // post some error or log it
  // send the post data