In one of my previous blog posts on Twitter API in AIR Mobile App, many blog readers had requested for coming up with a tutorial on working with Twitter API 1.1 I have been very lazy on my design/development aspects since quite long but wanted to revive those back. So, to start with my Flex/Flash skills, I thought to come up with a tutorial on using Twitter API 1.1 in an AIR Mobile App.

Basically, this won’t be much of a tutorial but a code share. To get step by step details, check this previous blog post: Twitter API in AIR Mobile App

I actually didn’t changed much in the previous code. Things which were changed mainly were the URLs and the request/response format.

public const VERIFY_CREDENTIALS:String = 
"https://api.twitter.com/1.1/account/verify_credentials.json";
//var postRequest:OAuthRequest = new OAuthRequest(OAuthRequest.HTTP_MEHTOD_POST, 
"https://api.twitter.com/1.1/statuses/update.json", {status:postTxtArea.text}, consumer, token);

The code also makes sure that the user details received from Twitter remain stored locally, so that the user doesn’t have to login again, even after the app is closed.

public function readTwitterAccess():void
{
var file:File = File.applicationStorageDirectory.resolvePath("tw.file");
var fileStream:FileStream = new FileStream();
if(file.exists){fileStream.open(file, FileMode.READ);
var obj:Object = fileStream.readObject() as Object;
twitterAccessObj.accessKey = obj.twitterAccessKey;
twitterAccessObj.accessSecret = obj.twitterAccessSecret;
fileStream.close();}else{trace("No File Present");}
}

public function writeTwitterAccess():void
{
var file:File = File.applicationStorageDirectory.resolvePath("tw.file");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
var obj:Object = {};
obj.twitterAccessKey = twitterAccessObj.accessKey;
obj.twitterAccessSecret = twitterAccessObj.accessSecret;
fileStream.writeObject(obj);
fileStream.close();
}

Download the FXP