Update your Twitter status from ColdFusion using a JSP tag library

Today I wanted to find an easy way to put a status update into my Twitter account using ColdFusion. I went searching the API docs, and found this page.

http://apiwiki.twitter.com/Libraries

Unfortunately, there are no CF examples listed, boo! However, there are some for Java, so I continued my search in that direction. Eventually I found this JSP taglib, and decided to give it a "Twirl" :)

http://www.servletsuite.com/servlets/twittertag.htm

To use any JSP taglib, you simply drop the .jar file into your /webroot/WEB-INF/lib/ directory. I believe it also requires the Enterprise edition of ColdFusion. A good article that fully explains their usage was done by Charlie Arehart back in May 2002.

After copying the file, you must then restart ColdFusion. This is a must or you will get an error when attempting to import the library.

That's it, I was now ready to test a Twitter post. Here is the sample code I used that will put a new status message in my Twitter account. I saved this in a file twitter.cfm, then browsed to the page on my local machine as http://localhost/twitter.cfm

<cfimport taglib="/WEB-INF/lib/twittertag.jar" prefix="twitter">
<twitter:update user="your_username_here" password="your_password_here" id="result">
My posting to Twitter from CF <cfoutput>#now()#</cfoutput>
</twitter:update>

Upon success, an XML dataset is returned in the "result" variable. If you cfdump it, looks like this.

<?xml version="1.0" encoding="UTF-8"?> <status> <created_at>Wed Feb 04 21:29:26 +0000 2009</created_at> <id>1177644114</id> <text>My posting to Twitter from CF {ts '2009-02-04 15:29:28'}</text> <source>web</source> <truncated>false</truncated> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <favorited>false</favorited> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>20062919</id> <name>Twin Cities CFUG</name> <screen_name>TCCFUG</screen_name> <location>St. Paul, MN USA</location> <description>Adobe ColdFusion User Group -of Minneapolis / St. Paul, Minnesota</description> <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/75391930/colderfusion_twitter_normal.jpg</profile_image_url> <url>http://groups.adobe.com/groups/bd9082a926/</url> <protected>false</protected> <followers_count>0</followers_count> </user> </status>

If you fail to restart CF, you will see this TagExtraInfo error message:

The TagExtraInfo class com.cj.twitter.strVariable for the update tag could not be found.

The CFML compiler was processing:
* A cfimport tag beginning on line 1, column 2.

This is not the best solution if you are in a shared hosting environment, as they may not install the twittertag.jar file for you. I'm curious what other methods developers have found to accomplish status posts to Twitter.

Comments
Chris Gottshall's Gravatar That's a good solution. I built a CFC to work with the Twitter API a while back, but I think using Java solutions are often overlooked. Thanks for posting this.
# Posted by Chris Gottshall | 2/6/09 10:15 AM
habeyhl's Gravatar Any idea what to do about this error:

com/cj/twitter/strVariable (Unsupported major.minor version 49.0)

I installed the Jar file as you directed so I'm not sure what's going on. I'm new to JSPs and APIs :\
# Posted by habeyhl | 2/23/09 5:21 PM
Troy's Gravatar @habeyhl, Look thru the comments on this Forta post, @Samson discusses the same error and how to fix.
http://www.forta.com/blog/index.cfm?mode=entry&...
# Posted by Troy | 2/27/09 9:53 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner