Retrieving recent tweets from Twitter (Web 2.0 Integration) (iPhone JavaScript)

Undoubtedly, Twitter is one of the most popular Web 2.0 applications on the Net. Many developers have found ways to connect this service to their iPhone applications .This recipe shows you how to load n tweets from a specific Twitter user. All of these tweets will be displayed in a simple list.

The required code for this recipe is a simple XHTML file called code/ch10/twitter. html in the code bundle.

Getting ready

First you need a Twitter account name; you may already have one. Then, make sure you’ve installed XUI and UiUIKit frameworks on your machine.

How to do it…

1. After creating a standard XHTML file with the required lines for loading both our frameworks, add the following lines to set up the user interface:

tmp19-160_thumb

2. Then, we’re going to add some JavaScript code for retrieving our last tweets:

tmp19-161_thumb


3. Finally, close and save your new file. After loading it on your device, you will see the result as is shown in the following screenshot:

tmp19-162_thumb

How it works…

The UiUIKit framework is used in this recipe for building our simple user interface. On the other hand, XUI helps us to process the result response sent by Twitter. In order to do that, we only need to use a JavaScript line for making a JSON request through AJAX. Actually, our recipe is using the Twitter username bsnux and we’re loading the latest five tweets posted by this user. For using your own user, just replace the mentioned username with a user of your choice. Also, you can change the number of the requested tweets by changing the value of the count variable.

The JavaScript my_tweets () function works as a callback, receiving the tweets and processing the response for creating our simple list.

There’s more…

We can modify our original recipe for displaying the profile picture of the owner of each tweet. The change is pretty simple, just replace the JavaScript line:

tmp19-163_thumb

With the following line:

tmp19-164_thumb

The result of loading this new application is shown in the next screenshot:

tmp19-165_thumb

See also

► Installing the UiUIKit framework recipe in topic 1, Frameworks Make Life Easier

► Installing the XUI framework recipe in topic 1, Frameworks Make Life Easier

Next post:

Previous post: