Tuesday, May 13, 2008

How to twitter from JSP

As per Twitter API in order to post new twit from the application you have to perform HTTP POST request to the following URL: http://twitter.com/statuses/update.xml

See how to do that easily with HTTP taglib from Coldtags suite:

<%@ taglib uri="taglib32.tld" prefix="t" %>

<t:GetPost url="http://twitter.com/statuses/update.xml" method="post">
  <t:setAuthorization user="your_twitter_name"
   password="your_twitter_password"/>
  <t:setParam name="status">test from JSP</t:setParam>
</t:GetPost>

tag setAuthorization defines a BASIC authentication scheme, so you have just provide here your twitter name and password. Tag setParam defines here
a parameter status (as per API requirements) with your message. So now you can post to twitter right from your JSP pages.

No comments: