As a follow on to my post about using bit.ly to shorten urls for submitting to twitter, today I want to talk about how to automatically submit a tweet from coldfusion to the twitter api using twitter4j. Before I go into how to post a tweet from coldfusion however I want to cover how Twitter authenticates status updates.

Twitter and Oauth

Before June/July of 2010 posting a status update to twitter was a simple matter of sending a username, password and tweet to the twitter api url. This method used the Basic Http Authentication system and was both simple and insecure.

After June/July Twitter switched over to using a method of authentication called OAuth. The OAuth method of authenticating a user/application work on the principle of shared and secret tokens being used to sign a specific request to the twitter api.

Advantages of OAuth

This method of authentication gives two main advantages. Firstly it is more secure and you never transmit your username or password when posting an update. Secondly it allows for users to authorise third party applications to send/recieve data from your twitter account without having to give them your password.

Disadvantages of OAuth

While very powerful, OAuth as implemented by twitter has two major downsides, which are essentially two sides of the same coin.

Firstly it is far more complicated to implement. A typical work flow of authenticating an application requires numerious detailed steps to complete.

Secondly as a result of the complexity of the signing method it is very difficult to diagnose problems. This is also not helped by the documentation which while thorough looks to be written by someone intimately familiar with OAuth for somebody who is intimately familiar with OAuth. Further there are no good tools available for developers (that I have found) that can help diagnose / demonstrate what the expected outcome of a particular step in the authentication process should be.

Implementing in ColdFusion

Currently there are no simple Coldfusion implementations for talking to twitter using OAuth. I have found a few libraries but they are considerably bloated for the simple process of posting a tweet. For this reason I have started developing my own simple library which I will cover at a later date.

In the mean time I want to show how I recently was able to post to twitter from Coldfusion using a java library.

Posting to Twitter using Twitter4j

Twitter4J is an unofficial Java library for the Twitter API which allows you to easily integrate your Java/Coldfusion application with the Twitter service. Installing and using is a simple matter of following the following steps.

Post a Comment

Comment Etiquette:

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain or appear to be advertisments, will not be published.

We are all adults here so play nice.

*
*



Mario Conforti's Gravatar
Mario Conforti
Monday, January 23, 2012 at 9:29:32 AM EST

Hi, thanks for the script, but as you can see at the URL I am getting this error:
The setOAuthConsumer method was not found.
Either there are no methods with the specified method name and argument types or the setOAuthConsumer method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
I used the latest version 2.2.6
Do you think this might be the problem?
Thanks
mc.

Mario Conforti's Gravatar
Mario Conforti
Monday, January 23, 2012 at 10:14:33 AM EST

The problem IS the version. I found an older twitter4j jar, and now evarything is fine.Thanks,
mc.

Steven Neiland's Gravatar
Steven Neiland
Monday, January 23, 2012 at 10:16:36 AM EST

Glad you were able to figure it out mario.

 

Archives Blog Listing

 

Tag Listing