Skip to content

Using Twitter oauth on GAE/J

by dkberktas on January 26th, 2010

Twitter supports oauth and there are many libraries for it, for  Java(twitter4J)(oauth-signpost),  most of the time you see examples of a desktop version, so it can take time to implement it on a web application (it did take time for my case).

Step 1. Get a Twitter account and create a Twitter application from http://twitter.com/apps (don’t forget to check in browser and enter a  valid callback url.

Step 2.  Download twitter4J add the library (in my case twitter4j-core-2.1.1-SNAPSHOT.jar) to project and update classpath

Step 3. Create a web application (I assume you have the Google plugin for Eclipse )

Step 4. Add the following servlets and update your web.xml. First servlet will handle login part. It will create a RequestToken which will create the magical aggrements between the consumer(your application) and provider(twitter). First servlet save the  token and secret token since we will need them later.

String token = requestToken.getToken();
String tokenSecret = requestToken.getTokenSecret();

Step 5. You forget to update web.xml didn’t you, update the web.xml

Step 6.  Enable session by adding

    <sessions-enabled>true</sessions-enabled>

to appengine-web.xml.

You can see my version from http://90.latest.denemekaya.appspot.com/login

ps. don’t forget to set the callback in Twittter to the url of the servlet for callback.

Links:

  • http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/
  • Explain the same procedure with Grails — http://blogs.bytecode.com.au/glen/2009/12/08/log-into-your-grails-app-using-your-twitter-credentials.html
4 Comments
  1. Nice to see another blog on Google App Engine and Twitter development.

  2. Very useful tutorial! I guess it saved me some trial and error.

Trackbacks & Pingbacks

  1. Tweets that mention Using Twitter oauth on GAE/J – dogan kaya berktas -- Topsy.com
  2. Twitter, OAuth, and GAE | GRG Components

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS