Create a Twitter OAuth Application With Tweetr Using Single Access Token

What do you do when you want to use the Twitter API with your own account, and don’t need or want users to login via the PIN OAuth dance? You can use a single access token/secret in place of the authenticated token/secret and get all the access you need.

Note: the authenticated user in this scenario is you, the owner of the application.

For this example I’m using Tweetr, an AS3 library for accessing Twitter from your Flash or Flex application. Tweetr requires as3crypto. Details and downloads here:

Make sure you grab the proxy php and load that up on your server so you can have a service host. Run the install.php so it’s ready to go. This is a nice script providing caching so you get a little speed boost and don’t run over your Twitter API limit.

Ok, let’s get to it.

Create a Twitter Application, and make note of the Consumer key and secret on the settings page. Then on the right side of the profile click the button labeled “My Access Token”. Grab that Access Token and Access Token Secret. This is referred to as a “single access token”, “one access token”, or “single user access token”. Docs:

In your Flash application, implement Tweetr with OAuth. Import and other implementation details are omitted below.

var serviceHost : String = “http://your_twittr_proxy_php_setup”;

var tweetr:Tweetr = new Tweetr();
tweetr.serviceHost = serviceHost;       

oauth = new OAuth();
oauth.serviceHost = serviceHost;
oauth.consumerKey = “CONSUMER_KEY”;
oauth.consumerSecret = “CONSUMER_SECRET”;
oauth.oauthToken = “MY_ACCESS_TOKEN”;
oauth.oauthTokenSecret = “MY_ACCESS_TOKEN_SECRET”;
tweetr.oAuth = oauth; 

And then you need to…wait, sorry, that’s all there is. Start making calls to the API and listening for results.

tweetr.addEventListener(TweetEvent.COMPLETE, handleLoad);
tweetr.addEventListener(TweetEvent.FAILED, handleFail);
tweetr.getUserTimeLine(null, null, null, 0, 0);

var tweets:Array = [];
private function handleLoad(event:TweetEvent):void
for(var i:int = 0; i

< event.responseArray.length; i++)
var statusData:StatusData = event.responseArray

  // ... do something magical with the tweets

private function handleFail(event:TweetEvent):void
trace("Failed to get data");
// ... handle the disappointing failure…maybe a whale…just a thought

There are plenty of good tutorials out for using Tweetr, though beware of any too old. Twitter phased out basic authentication August 2010.

A couple I checked out:
Mark Doherty: Tweetr App Video Walkthrough
swfjunkie: PINless OAuth with Tweetr

I also want to note that it’s difficult to secure anything in a Flash application, and the key, token, and secrets are no exception. In this example they are right there in the code, unencrypted. SWFs are easily decompiled. If you dream up a solid security solution that doesn’t require a mountain of effort, please let me know.

Categories: FlashFlexAIRPermalink

Flex Hero Gotcha: Application Freeze on navigator.popView and navigator.popToFirstView

I’ve been spending a lot of time in Flex “Hero” preview release since it was released Sunday evening. Overall it’s quite good, I’m very happy to have it, and I’ve been able to do what I need to with my pretty basic app.

I ran into a pretty disconcerting gotcha and I wanted to post it here in case anyone else happens upon this.


You navigate back to a previous view via navigator.popView() or navigator.popToFirstView() and the application stalls without an error

How to Reproduce It

If you are using the Employee Directory from the sample apps as your jumping off point, the EmployeeDirectoryHome.mxml has a search box and button in the navigation area. That’s fine and the app runs.


text="{SEARCH_TEXT}" focusIn="searchKey.text=''" enter="search()"/>



Move the search box and button into an HGroup and positioned it below the navigation. Suddenly any call to navigator.popView() will go into la la land and the entire app will freeze. No error is thrown. Eventually, if you’re running on a device, you’ll be prompted to kill the app or wait. Don’t bother waiting.


text="{SEARCH_TEXT}" focusIn="searchKey.text=''" enter="search()"/>




With the keen eye and assistance of Jason Hanson, we determined that the measuring and drawing of content in the actionContent and navigationContent must happen at a different stage than the rest of the visual children. The width of the TextInput was being calculated instead being set as a percentage, and it was removing that calculation that fixed the issue. So, changing the width to 100% causes the TextInput to “greedily”, as Jason would say, take up all available space left by the button and the app once again works just fine.




I’ve logged a JIRA bug for this issue.

Hero is definitely prerelease and this is one example of where that shows up.

I highly recommend you check out the Shopping Cart Application for Web and Mobile to see more advanced solutions. Thanks Jason!


Categories: FlexAIRPermalink

Speaking at Flash Camp St. Louis

I’m excited to be speaking at Flash Camp St. Louis coming up very soon on September 3rd. Come get a jump on your holiday weekend and join us at the City Museum for a full day of great sessions and mingling.

Be sure to register right away. Space is limited, and it’s only $60 for a full day of sessions, lunch, and probably some free giveaways.

I really hope that my session will have some appeal for both developers and designers. I’ll be focusing on asset management in more advanced, dynamic, or heavier projects. When you have a Flash project with a lot of logic and thus code, and you’re talking to databases and social networks, you find that working with just a Flash FLA file isn’t enough. But how can you continue to utilize the strengths of Flash Pro for animation, composite components, vectors, and general layout? And what do you do about video, audio, social network content, xml, json, and other data sources?

I’ll be looking at different ways to address these questions, the developer and designer workflows involved, and the libraries and tools I’ve found most useful in the process.

To wet your appetite, here is an 18 minute screencast I put together covering one such strategy, the use of a SWC file to provide assets to an Actionscript or Flex project.

Use Flash Pro Assets in Actionscript and Flex Projects from David Ortinau on Vimeo.

In this screencast I use one of my favorite tools, FDT from PowerFlasher. I don’ think I mention it in the screencast, so let me highlight the 2 keystroke combinations you need to master in order to unleash all of the amazing tricks you’ll see me do.

Quick Fix - CMD + 1 (CTRL + 1 on the PC I think)
This fixes missing imports, generates var declarations, initiates new classes, generates handlers, and on and on

Code Complete - CTRL + SPACE
This keystroke is also present in Flash Builder, but has some extra oomph it seems in FDT. Type part of anything and hit it to see options on what you might mean. Also generate constructors or other code blocks.

Hope to see you at Flash Camp!

Flash Camp St. Louis

September 3, 2010
9am - 4pm
The City Museum

Categories: FlashFlexFreelancingAIRProductivityPermalink