Build Zk Mobile Twitter Application in 15 Minutes

Jeff Liu, Engineer, Potix Corporation
July 24, 2007

Version & Requirement

  • ZK Mobile 0.8.5
  • jTwitter - Open-source Java Interface to Twitter
  • twitterHelper

Introduction

"Twitter is the app that people loves to hate." Clive Thompson states this on June issue of Wired magazine. Twitter is the app that people can sumbit thier activities and thoughts from website, IM, cellphone and many. By its public timeline service, you can observer what are people doing around the world. Now, you can build up a mobile web application to view twitter updates by ZK Mobile framework in 15 minutes

 

The Required Libraries

jTwitter - Open-source Java Interface to Twitter

jTwitter is a well implemented java interface, developed by Daniel Winterstein. It is very well implemented and effortless to adapt from. If you are interested, here is the url to its website http://thinktankmaths.co.uk/java-twitter

twitterHelper

The wrapper for jTwitter classess are contained in twitterHelper.jar. Since some classes in jTwitter package don’t come with getter and setter methods, twitterHelper classes are implemented for “wrapping” jTwitter classes with getter and setter methods.
Source Code

Install the Demo

  1. Setup the Sun's wireless toolkit environment. Please refer to ZK Mobile Quick Start
  2. Download the zkMobTwitter.war
  3. Deploy it by Tomcat manager or extract folder into TOMCAT_PATH\webapps\

ZK Mobile Twitter

Live Demo



Complete Code -twitter.mil

<frame onCommand="MilDevice.goHome(null)" visible="true">
<zscript>
<![CDATA[

import thinktank.twitter.*;
import twitterHelper.*;

//Create a twitter object by user's username and password
Twitter myTw = new  Twitter("USERNAME","PASSWORD");

//Create a twitter status factory;
TwitterFactory _tf = new TwitterFactory();

//Create list of status
List updates = _tf.myTwitterStatus(myTw);

]]>
</zscript>
	<zk  forEach="${updates}" >
		<label flow="only" value="[${each.userScreenName}]"/>
		<label flow="only" value="${each.text}"/>
		<label flow="last" value="Where: "/>
		<label flow="only" value="- END -"/>
	</zk>
	
	<command label="Home"  type="back"/>
</frame>
	

Here, we use a simple forEach attribute to display the messages from list of updates.

Todo List

  1. Download jTwitter package ( 1 minutes )
  2. Download Sun's wireless toolkit environment ( 2 to 3 minutes )
  3. Code jTwitterHelper (source code) and pack it into jar file ( 5 minutes )
  4. Code twitter.mil ( 3 minutes )
  5. Deploy and test ( 3 minutes )

Download

Summary

In this sample, a little bit part of jTwitter interface is demonstrated. If you like twitting, please try it out and give us any feedback. Please, feel free to post it on ZK forum.