Link to home
Start Free TrialLog in
Avatar of theabbeyschool
theabbeyschoolFlag for United Kingdom of Great Britain and Northern Ireland

asked on

HTML Code to Update Twitter

Hi, I have the code below that I have found on the Internet. Unfortunately it doesn't work, does anyone know how I can update it to make it work and authenticate with Twitter?

Regards


<form action="http://twitter.com/statuses/update.xml" method="POST" enctype="application/x-www-form-urlencoded">   <!-- set your Twitter username and password here --><input type="hidden" name="user" value="{ TWITTER USERNAME }" /> <input type="hidden" name="pswd" value="{ TWITTER PASSWORD }" />   status <input type="text" name="status" maxlength="140" /> <input type="submit" value=" tweet! " /> </form>

Avatar of theabbeyschool
theabbeyschool
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I've also tried this code but it has the same problem, it cannot authenticate:

<html> 
<head> 

     <title>VbScript Tweets - Update your Twitter status</title> 

     <hta:application 
          id="objVbTweet" 
          applicationname="objVbScriptTweets" 
          scroll="yes" 
          scrollflat="yes" 
          border="thin" 
          borderstyle="normal" 
          caption="yes" 
          icon="explorer.exe" 
          showintaskbar="yes" 
          singleinstance="yes" 
          sysmenu="yes" 
          windowstate="normal" 
          navigable="no" 
          scrollflat="yes" 
          contextmenu="yes" 
          selection="yes" 
          singleinstance="yes" 
          minimizebutton="yes" 
          version="1.0" 
     /> 


     <style type="text/css"> 
     <!-- 
      
     /* General styles */ 
      
     body     {      
          margin: 0px; 
          padding: 0px; 
     } 


     /* format specific */      

     #header { 
          background-color:#c6e2ee; 
          border-bottom: 1px solid #000000; 
          padding: 10px; 
          font-family: verdana, arial, helvetica, sans-serif; 
          font-size: 10px; 
     } 

     #twitterboxarea{ 
          padding: 20px; 
          text-align:center; 
          font-family: verdana, arial, helvetica, sans-serif; 
          font-size: 20px; 
     } 


     #inputboxed { 
          font-family: verdana, arial, helvetica, sans-serif; 
          font-size: 20px; 
          font-weight: bold; 
          background-color: #F3F3F3; 
     } 

     #twitterresponse { 
          padding: 10px; 
          font-family: verdana, arial, helvetica, sans-serif; 
          font-size: 10px; 
          text-align: center; 
     } 
      
     .vbtweetstd { 
          vertical-align: text-top; 
          font-family: verdana, arial, helvetica, sans-serif; 
          font-size: 10px; 
     } 
      
     .buttonclass { 
          font-family: verdana, arial, helvetica, sans-serif; 
          font-size: 12px; 
          font-weight: bold; 
          border: 1px solid #000000; 
          width: 200px; 
          height: 50px; 
          background-color: c6e2ee; 
     } 
     --> 
     </style> 

</head> 

<script language="vbscript"> 

     OPTION EXPLICIT 'Be sure you have al your variables declared. 

     '--------------------------- 
     ' SETTINGS 
     ' The below values are the only values you have to change to get this script working 
     '--------------------------- 

     Const conUsername = "Twitter username" ' Your Twitter username 
     Const conPassword = "Twitter password" ' Your Twitter password 


     Sub DoTwitter 
          ' This sub is built in to perform some checks 
          Dim strTwitterMessage 
          strTwitterMessage = TxtTwitter.value 
           
          If Len(strTwitterMessage) > 140 Then 
               ' In case you message is too long, it drops a warning.. 
               twitterresponse.InnerHTML = "Your message is more then 140 characters, Twitter will post it, "& _ 
                    "but your followers have to click on your message to read the entire story. " & _ 
                    "It is recommended to make your message shorter then 140 characters...<br /><br /><br />" & _ 
                    "To continue anyway, click yes, otherwise change your message and click the &quot;Send to twitter&quot; button again.<br /><br />" & _ 
                    "<input class=""buttonclass"" type=""button"" value=""Yes... (please continue!)"" OnClick=""SendToTwitter"" />" 
                     
          ElseIf Len(strTwitterMessage) = 0 Then 
               ' In case you did not enter a message at all... 
               twitterresponse.InnerHTML = "You did not enter a message..." 
                
          Else 
               ' Otherwise, call the sub to post your message to Twitter 
               SendToTwitter 
          End If 

     End Sub 


     Sub SendToTwitter      

          ' This is the function wicht does all the work. 
          ' It uses XMLHTTP to post your message to Twitter.. 
          Dim objHTTP , strSendToTwitter 
          Set objHTTP = CreateObject("Microsoft.XMLHTTP") 
           
               objHTTP.open "POST", "http://twitter.com/statuses/update.xml", false, conUsername, conPassword 
               objHTTP.send "status=" & TxtTwitter.value & " test.."           
                
               ' The function stores the Twitter response to a variable so you can use that response later 
               strSendToTwitter = objHTTP.responseText 
           
          Set objHTTP = nothing 'Release the object 
           
          ' Now do something with the result. It's not 
          ' necessary for the script to work, but it is nice to use it later 
          ReadXMLFile(strSendToTwitter) 
           
     End Sub 
      

     Sub ReadXMLFile(strXML) 
           
          ' This sub make the XML response readable. 
          ' it formats the XML into a table layout, but you can 
          ' easily change this to a more advanced solution like 
          ' a logfile or something. 
           
          Dim xmlDoc 
          Set xmlDoc = CreateObject("Microsoft.XMLDOM") 
          xmlDoc.async="false" 
          xmlDoc.loadXML strXML 
           
          Dim strMessage 
          strMessage = "<table border=""0"">" 
           
          ' Perform a loop through all the childnodes 
          Dim x 
          For Each x In xmlDoc.documentElement.childNodes 

               strMessage = strMessage & "<tr><td class=""vbtweetstd""><b>" & x.nodename & "</b></td><td class=""vbtweetstd"">: </td><td class=""vbtweetstd"">" & x.text & "&nbsp;</td></tr>" & VbCrlf 
          Next 
           
          Set xmlDoc = nothing ' Release the object 
           
          ' Close the table 
          strMessage = strMessage & "</table>" 
           
          ' Drop the formatted HTML table into the message area.. 
          ' It is still some pretty rough output a user can't do anything with, 
          ' but I don't want to make the code too long.. 
          twitterresponse.InnerHTML = "<strong>Twitter responded:</strong><br /><br /><br />" & strMessage 
           
     End Sub 
      

     Sub CountCharacters 
      
          ' Show how many characters are used so far. 
          ' This sub is called each time you release a keyboard button. 
          twitterresponse.InnerHTML = Len(TxtTwitter.value) & " characters used.." 
           
     End Sub 

</script> 

<body> 

<!-- Start Header, modify or delete as you like! --> 
<div id="header"> 

     <strong>SITEJUNCTION</strong><br /> 
     <small>TWITTER STATUS UPDATE</small> 
     <br /><br /> 
     With this hta script you can update your Twitter status <br /> 
     more info: <a href="http://sitejunction.awardspace.com/vbscript_tweets/hta_script/" target="_blank">http://sitejunction.awardspace.com/vbscript_tweets/hta_script/</a> 
      
</div> 
<!-- End Header --> 


<!-- Start Twitter message box--> 
<div id="twitterboxarea"> 

     Enter your Twitter message in the box below; 
     <br /><br /> 
     <input type="text" id="inputboxed" size="50" name="TxtTwitter" OnKeyUp="CountCharacters" maxlength="400" /><br /><br /> 
     <input class="buttonclass" type="button" onclick="DoTwitter" value="Send to Twitter.." /><br /><br /> 
      
</div> 
<!-- End Twitter message box--> 


<!-- Messages appear here--> 
<div id="twitterresponse"></div> 
<!-- End of Messages box --> 

</body> 
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial