While working on an AIR Mobile app, either in Flash or Flex, you might want to integrate Twitter API in it. In one of my projects few months back, I wanted to integrate the Twitter API within the app but wasn’t able to find a complete working solution. While searching on the internet, I came across this article on Adobe DevNet. Though any complete example was not available, it proved to be a very helpful starting point. The approach doesn’t uses any specific Twitter API library but instead uses the default oAuth authentication mechanism used by Twitter.

In this article I’ll show you a simple example to create a Twitter API integrated Flex Mobile App that can post to Twitter and also verify user’s credentials.

To start with the project you would need to have two AS3 libraries:

Next, go to https://dev.twitter.com/ and create a new application. Once there, fill in the required details and add a website URL and a callback URL. Make sure what you use as the callback URL as we will need it later in the application.

Flex AIR AS3 Mobile Twitter API

Once done, go to the newly created application and change the Application Access Level to Read and Write. This is required as we will be using our app to publish tweets. Once this is done, take a not of the Consumer Key and Consumer Secret associated with this app. We will need this in our Flex Mobile App.

Next, go to Flash Builder and create a new Flex Mobile App. You can chose any App style, I selected a View Navigator App. Add the Crypto library and oAuth library to your project.

In the first view of the application, we write code to create a connection to the Twitter API, get user’s permission to allow application to read and write to his account, store the user’s access key and access secret locally and using these, read/write to user’s twitter profile. We store the details so that we can re use them for subsequent app accesses. Each time we start the app, we first verify if the locally stored access key and secret is valid.

The code for all this is written below and accompanied by self explanatory comments.

[cc lang=”actionscript3″]




This is just a simple example to show how you can post to Twitter using oAuth library in an AIR Mobile App.

Hope you find this a helpful one.

UPDATE: Check this newer post which uses Twitter API 1.1