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.

3 comments:

Rodrigo Alves said...
This comment has been removed by the author.
Rodrigo Alves said...

Could not read/save response from http://twitter.com/statuses/update.xml

Abava said...

>Could not read/save response from >http://twitter.com/statuses/update.xml

just tested - yes, it works. Feel free to submit your JSP code (part of it) related to this component to info@servletsuite.com We do support our components. We will check it out with our own id/password